【问题标题】:Wordpress: get last post belonging to a category, when listing categoriesWordpress:在列出类别时获取属于某个类别的最后一篇文章
【发布时间】:2009-10-12 22:37:17
【问题描述】:

我已尝试查看数据库,但似乎无法通过查询来执行此操作。如何仅查找一个类别的帖子,或者更具体地说,我只需要该类别中最后一个帖子的 ID。

我正在尝试在 index.php 中执行此操作

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    使用get_posts 可以满足您的需求,documentation here

    类似以下内容

    <?php
      $postsincat = get_posts(array("cat" => 1, "showposts" => 1));
      $idoflatestpostincategory = $postsincat[0]->ID;
    ?>
    

    您也可以在数组中使用category_name 代替cat 来使用名称代替ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      相关资源
      最近更新 更多