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

时间:2011-03-28 15:12:12

标签: php wordpress

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

2 个答案:

答案 0 :(得分:0)

您可以使用WP_Query获取所需内容。它非常灵活,你一定要开始使用它。 它就像SQL查询一样。

答案 1 :(得分:0)

在循环之前声明一些将保留帖子类别的var。比查询该猫的帖子。

以下是示例:

<?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; ?>
相关问题