douren8379 2012-10-31 21:00
浏览 35
已采纳

如何仅显示WordPress中最新类别的自定义分类的帖子

I have a custom taxonomy called Issues (like magazine issues) with categories named after the title of each issue. I created a page called "Current Issue" and added a link to it in the main navigation of the site.

This is the loop I have in the page template now:

$categories = get_terms('issue', 'orderby=count&order=asc');
     foreach( $categories as $category ): 
     ?>
     <h3><?php echo $category->name; ?></h3>
     <?php
     $posts = get_posts(array(
     'post_type' => 'issue_posts',
     'taxonomy' => $category->taxonomy,
     'term' => $category->slug,
     'nopaging' => true,
     ));
     foreach($posts as $post): 
     setup_postdata($post); 

It does order the categories and posts appropriately, but this pulls in all the posts for all the categories. I need the link to show only the most recently added category.

  • 写回答

2条回答 默认 最新

  • dongmo9996 2012-10-31 23:33
    关注

    The most recently added term will be the one with the highest ID. Fetch a single term ordered by ID in descending order and you will have the one most recently added.

    $args = array(
        'number' => 1,
        'orderby' => 'ID',
        'order' => 'DESC'
    );
    
    $recent_issue = get_terms( 'issue', $args );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探