[英]wordpress - other posts of the same category on post page
我需要在wordpress中的帖子内容之后链接相同类别的最后5个帖子。 有人可以帮助我吗? 谢谢
在循环之前,声明一些将保存帖子类别的变量。 比查询与那只猫的帖子。
这是示例:
<?php
$cat_id = 0; // declare var
if(have_posts()):
while(have_posts()):
// do what you usually do
$cat_id = $post->post_category;
endwhile;
endif;
// here you will get posts and make html output
$last_in_cat = get_posts('posts_per_page=5&cat='.$cat_id);
foreach($last_in_cat as $cat_post):
?>
<a href="<?php $cat_post->guid ?>"><?php $cat_post->post_title ?></a>
<?php endforeach; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.