関連記事 っぽいものを 付けてみました
この記事は 2016年 2月 17日 に書かれた記事です。
この記事は WordPress Version 4.4.2 の時の記事です。
僕が運用している このサイト 直帰率 が 90% 近いので
投稿についている タグ を キー として 投稿を 取得して 対策してみました
今は SNSボタンの上に 表示させてみました
これで 少しは 回遊性が上がるのでしょうか??
(´・ω・`)
まぁ 弱小サイトなので 回遊性が 低いのは 仕方ないのかもしれませんが…
というわけで
今回作成したコードを 公開しておきます
<?php
$post_tags_object = get_the_tags();
if( ! empty( $post_tags_object ) ) :
foreach( $post_tags_object as $tag ) {
$post_tags[] = $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' ); ?> »</a>
</div>
</article>
<?php endwhile; ?>
</section>
<?php
endif;
endif;
wp_reset_postdata();
?>