Stinger3をカスタマイズする上で参考頂けるであろう
single.phpの構造を簡単にご説明致します。
Google用ぱんくず
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<div class="kuzu"> <div id="breadcrumb"> <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> <a href="<?php echo home_url(); ?>" itemprop="url"> <span itemprop="title">ホーム</span> </a> > </div> <?php $postcat = get_the_category(); ?> <?php $catid = $postcat[0]->cat_ID; ?> <?php $allcats = array($catid); ?> <?php while(!$catid==0) { $mycat = get_category($catid); $catid = $mycat->parent; array_push($allcats, $catid); } array_pop($allcats); $allcats = array_reverse($allcats); ?> <?php foreach($allcats as $catid): ?> <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> <a href="<?php echo get_category_link($catid); ?>" itemprop="url"> <span itemprop="title"><?php echo get_cat_name($catid); ?></span> </a> > </div> <?php endforeach; ?> </div> </div> <!--/kuzu--> |
[Я]パンくずリストをGoogle検索結果にも表示・反映させる方法
更新日付きの投稿日とカテゴリ、タグの表示
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<div class="blogbox"> <p><span class="kdate">公開日: <time class="entry-date" datetime="<?php the_time('c') ;?>"> <?php the_time('Y/m/d') ;?> </time> : <?php if ($mtime = get_mtime('Y/m/d')) echo ' 最終更新日:' , $mtime; ?> </span> <?php the_category(', ') ?> <?php the_tags('', ', '); ?> <br> </p> </div> |
WordPress 記事の見直しと最終更新日の表記。それを Google に伝える
関連記事の表示
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<!--関連記事--> <h4 class="kanren">関連記事</h4> <div class="sumbox02"> <div id="topnews"> <div> <?php $categories = get_the_category($post->ID); $category_ID = array(); foreach($categories as $category): array_push( $category_ID, $category -> cat_ID); endforeach ; $args = array( 'post__not_in' => array($post -> ID), 'posts_per_page'=> 10, 'category__in' => $category_ID, 'orderby' => 'rand', ); $st_query = new WP_Query($args); ?> <?php if( $st_query -> have_posts() ): ?> <?php while ($st_query -> have_posts()) : $st_query -> the_post(); ?> <dl> <dt> <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"> <?php if ( has_post_thumbnail() ): // サムネイルを持っているときの処理 ?> <?php echo get_the_post_thumbnail($post->ID, 'thumb110'); ?> <?php else: // サムネイルを持っていないときの処理 ?> <img src="<?php echo get_template_directory_uri(); ?>/images/no-img.png" alt="no image" title="no image" width="110px" /> <?php endif; ?> </a> </dt> <dd> <h4 class="saisin"> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h4> <p class="basui"> <p><?php echo mb_substr( strip_tags( stinger_noshotcode( $post->post_content ) ), 0, 50 ) . ''; ?></p> <p class="motto"><a href="<?php the_permalink(); ?>">記事を読む</a></p> </dd> </dl> <?php endwhile; ?> <?php else: ?> <p>記事はありませんでした</p> <?php endif; wp_reset_postdata(); ?> </div> </div> </div> |
関連記事は、同じカテゴリで表示ページと同一ではないものをランダムで表示しています。
Googleアドセンスの表示
1 2 3 |
<div style="padding:20px 0px;"> <?php get_template_part('ad');?> </div> |
アドセンスはウイジェットで記載したものを計3か所表示しています。
(スマホは2つ)
なので、いらない場合は上記コードを削除すればOKです。
ページナビ
1 2 3 4 5 6 7 8 9 |
<!--ページナビ--> <div class="p-navi"> <p> PREV : <?php previous_post_link('%link', '%title', TRUE, ''); ?> <br/> NEXT : <?php next_post_link('%link', '%title', TRUE, ''); ?> </p> </div> |
ページナビはfunctionsのコードと連動しています。