简体   繁体   English

如何按类别获取最新帖子?

[英]How do i get latest post by category?

currently i am stuck with the problem .my code is 目前我陷入了问题。我的代码是

$category_ids = get_all_category_ids();

    foreach($category_ids as $kk=> $cat_id) {

      $cat_name= query_posts( 'posts_per_page=1&orderby=date&order=ASC&cat='.$cat_id);

    if (have_posts ()) :while(have_posts()):the_post

this is the code i write in my loop.php file what i want is to take only latest post by category showing only 1 post of each category by date 这是我写在loop.php文件中的代码,我想要的是仅按类别显示最新帖子,按日期仅显示每个类别的1个帖子

You can download a plugin like this and find out how it is done. 你可以下载一个插件像这样 ,看看它是如何做。 Also, this thread has something that may help you. 另外, 线程可能会对您有所帮助。 It contains a snippet that shows the last post in each of a list of categories. 它包含一个片段,显示每个类别列表中的最后一个帖子。 Wold post the code, but it craps up the formatting, sorry. 请张贴代码,但是不能简化格式,抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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