繁体   English   中英

wordpress-帖子页面上相同类别的其他帖子

[英]wordpress - other posts of the same category on post page

我需要在wordpress中的帖子内容之后链接相同类别的最后5个帖子。 有人可以帮助我吗? 谢谢

您可以使用WP_Query获得所需的内容 它非常灵活,您绝对应该开始使用它。 就像SQL查询一样。

在循环之前,声明一些将保存帖子类别的变量。 比查询与那只猫的帖子。

这是示例:

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM