スニペット/WordPress basic tags
1 | <?php the_post_thumbnail(); ?> |
1 | <?php the_title(); ?> |
1 | <?php echo esc_url(get_template_directory_uri() ); ?> |
time
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php if ($mtime = get_mtime('Y/m/d')) echo '<li>更新:' . $mtime . '</li>'; ?> <li><i class="fa fa-folder-open-o" aria-hidden="true"></i> <?php $cats = get_the_category(); $exclude = array(); // 非表示にしたいカテゴリID $str = ''; foreach ((array) $cats as $cat) { if (!in_array ($cat->cat_ID, $exclude)) { $str .= '<a href="' . get_category_link($cat->cat_ID) . '">' . $cat -> cat_name . '</a>' . ', '; } } echo rtrim ($str, ", "); // 末尾のカンマ削除 ?> |
global menu
1 2 3 4 5 6 7 8 | <?php wp_nav_menu(array( 'theme_location'=>'header_menu', 'container' =>'nav', 'container_id' => 'global-nav', 'container_class' => '', 'menu_id' => '', 'menu_class' =>'')); ?> |
pagination
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | // ページ数と総ページ数 function show_page_number() { global $wp_query; $paged = (get_query_var('paged') ) ? get_query_var('paged') : 1; $max_page = $wp_query->max_num_pages; echo $paged.'/'.$max_page; } // ページ送り function bones_page_navi() { global $wp_query; $bignum = 999999999; if ( $wp_query->max_num_pages <= 1 ) return; echo '<nav class="pagenation">'; echo paginate_links( array( 'base' => str_replace( $bignum, '%#%', esc_url( get_pagenum_link($bignum) ) ), 'format' => '', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages, 'prev_text' => '前へ', 'next_text' => '次へ', 'type' => 'list', 'end_size' => 2, 'mid_size' => 2 ) ); echo '</nav>'; } |
1 2 3 4 5 6 7 | <?php global $wp_query; $total_results = $wp_query -> found_posts; ?> <?php if (is_home() || is_category() || is_search()&&has_category(0)): ?><?php echo $total_results; ?>件<?php endif; ?>(<?php show_page_number(); ?>ページ)</p> <?php bones_page_navi(); ?> |
functions.php
1 2 3 | <?php require_once locate_template('functions/admin.php'); ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // ページタイトル add_theme_support('title-tag'); // アイキャッチ add_theme_support('post-thumbnails'); set_post_thumbnail_size('auto', 'auto', false); // RSSアイキャッチ function rss_thumbnail($content) { global $post; if (has_post_thumbnail($post->ID)) { $content = '<div><a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, 'full') .'</a></div>' . $content; } return $content; } add_filter( 'the_excerpt_rss', 'rss_thumbnail'); add_filter( 'the_content_feed', 'rss_thumbnail'); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // 不要コード削除 remove_action('wp_head', 'rel_canonical'); remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'wp_shortlink_wp_head'); remove_action('wp_head', 'wp_print_styles', 8); remove_action('wp_head', 'wp_print_head_scripts', 9); remove_action('wp_head', 'wp_print_footer_scripts', 20); remove_action('wp_head', 'print_emoji_detection_script', 7 ); remove_action('admin_print_scripts', 'print_emoji_detection_script' ); remove_action('wp_print_styles', 'print_emoji_styles' ); remove_action('admin_print_styles', 'print_emoji_styles' ); // 画像の属性削除 add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text'); function remove_image_text($attr) { unset($attr['alt']); unset($attr['class']); return $attr; } // サムネイルの属性削除 add_filter( 'post_thumbnail_html', 'custom_attribute' ); function custom_attribute($html){ $html = preg_replace('/class=".*\w+"\s/', '', $html); return $html; } |
コメントを投稿する