てくてくあるく

WordPress の テーマ とか プラグイン に ついて 勉強しています

僕が運用している このサイト 直帰率 が 90% 近いので
投稿についている タグ を キー として 投稿を 取得して 対策してみました

今は SNSボタンの上に 表示させてみました

これで 少しは 回遊性が上がるのでしょうか??
(´・ω・`)

まぁ 弱小サイトなので 回遊性が 低いのは 仕方ないのかもしれませんが…


というわけで
今回作成したコードを 公開しておきます

<?php
  $post_tags_object = get_the_tags();
  if( ! empty( $post_tags_object ) ) :
    foreach( $post_tags_object as $tag ) {
      $post_tags&#091;&#093; = $tag->term_id;
    }
    $args = array(
      'orderby'        => 'rand',
      'post__not_in'   => array( get_the_id() ),
      'tax_query'      => array(
                            array(
                              'taxonomy' => 'post_tag',
                              'terms'    => $post_tags,
                            ),
                          ),
      'posts_per_page' => 3,
    );
    $the_query = new WP_Query( $args );
    if( $the_query->have_posts() ) :
?>
<section class="row">
<?php
      while( $the_query->have_posts() ) :
        $the_query->the_post();
?>
  <article <?php post_class( array( 'col-md-4' ) ); ?>>
    <div class="card">
      <div class="card-block">
        <h2 class="card-title h6"><?php the_title(); ?></h2>
      </div>
      <a href="<?php the_permalink(); ?>" class="card-footer-link card-footer-link-secondary"><?php _e( 'more', 'bootstrap-theme' ); ?> &raquo;</a>
    </div>
  </article>
<?php endwhile; ?>
</section>
<?php
    endif;
  endif;
  wp_reset_postdata();
?>

Related Article

自作 テーマ を テーマユニットテスト で 検査してみた

詳細へ »

archives の tag ページ が 崩れていた ので 修正した

詳細へ »

親テーマのメニューを非表示にしてみた

詳細へ »