【问题标题】:Display all posts from latest taxonomy in wordpress在 wordpress 中显示来自最新分类法的所有帖子
【发布时间】:2012-04-03 15:12:08
【问题描述】:

我正在创建一个有卷和期的报纸网站。数量每年增加,问题每周增加。我创建了一个带有问题分类的自定义帖子类型的文章。

目前,下面的代码将从具有最新问题分类的文章中获取最新帖子。我希望它获取最新一期的所有帖子。我发现我可以通过将 $issue[0]->slug 更改为 $issue[1]->slug 来获得下一篇文章。我意识到我只需要一个循环,但我无法弄清楚。

感谢您的帮助。

<?php
$issue = get_terms('issue','orderby=none&order=DESC');
$latest_edition = $issue[0]->slug;

query_posts('&post_type=article&gdsr_sort=thumbs&gdsr_order=desc&issue='. $latest_edition) . '&showposts=99'; ?>

【问题讨论】:

    标签: php wordpress loops taxonomy custom-post-type


    【解决方案1】:

    您没有循环浏览您的帖子。您需要执行以下操作:

    // Returns an array issues
    $issue = get_terms('issue','orderby=none&order=DESC');
    
    // You want the most recent issue
    // i.e. that which has an array key of 0
    $latest_edition = $issue[0]->slug;
    
    // Return all the posts for this issue
    query_posts('&post_type=article&gdsr_sort=thumbs&gdsr_order=desc&issue='. $latest_edition) . '&showposts=99';
    
    // Loop through each post
    while ( have_posts() ) : the_post();
       // Echo out whatever you want
       echo '<li>';
       the_title();
       echo '</li>';
    endwhile;
    

    【讨论】:

    • 我有一个类似的 while 循环——即使该分类法中至少有 5 个结果,它也只使用 1 个结果。还有其他想法吗?
    • 也许摆脱所有其他搜索条件,只使用query_posts('issue='.$latest_edition);
    • 我认为问题在于 post_type 以 & 开头 - 无论哪种方式,使用该查询字符串都会产生一个工作参数和快乐的程序员!谢谢老兄!
    【解决方案2】:

    感谢@hohner 的回答。它确实帮助我继续解决我的问题。 @Aaron Snyder 对于完整的结果,您可以添加一些带有您的分类信息的循环,以显示所有帖子结果

    $latest_edition = $issue[0]->slug;
    $latest_edition = $issue[0]->term_id;
    $postsart = get_posts(array(
    'showposts' => -1,
    'post_type' => 'articles',
    'tax_query' => array(
    array(
    'taxonomy' => 'articles-tax',
    'field' => 'term_id',
    'terms' => $latest_edition)
    ))
    );
    

    试试它对我有没有帮助,看看它是否对你有帮助

    【讨论】:

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