Q.関連記事の表示をランダム表示から新着順に変更したい
関連記事は、同カテゴリーの記事をランダムに表示されていると思いますが、同カテゴリーを新着順に表示させるには、どうすればよいでしょうか?
A.下記のphpファイルの該当箇所を編集してください
編集するファイル:single.php
編集する箇所:
下記ファイルの「rand」を「date」に変更してください。
変更前
<?php // related post
if ($options['show_related_post']) :
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>5,
'orderby' => 'rand'
);
変更後
<?php // related post
if ($options['show_related_post']) :
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>5,
'orderby' => 'date'
);
この記事は役に立ちましたか?
もし参考になりましたら、下のボタンで教えてください。
今後の記事作成の参考とさせて頂きます!