0
我需要在wordpress中的帖子内容后链接最后5个相同类别的帖子。任何人都可以帮助我?谢谢wordpress - 帖子页面上的同一类别的其他帖子
我需要在wordpress中的帖子内容后链接最后5个相同类别的帖子。任何人都可以帮助我?谢谢wordpress - 帖子页面上的同一类别的其他帖子
在循环之前声明一些var将保存post类别。比查询与该猫的帖子。
这里是例如:
<?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; ?>
你可以使用WP_Query获得你想要的信息。它非常灵活,你应该开始使用它。 它就像SQL查询一样。