在wordpress中显示最新分类法中的所有帖子


Display all posts from latest taxonomy in wordpress

我正在创建一个报纸网站,该网站将有《卷与问题》。数量每年递增,发行量每周递增。我已经创建了一个自定义的文章类型的问题分类法。

目前,下面的代码将从具有最新问题分类法的文章中获得最新的文章。我希望它能得到最近一期的所有帖子。我发现我可以通过将$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'; ?>

您不会循环浏览您的帖子。你需要做一些类似的事情:

// 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;

感谢@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)
))
);

试试它对我有帮助,并告诉你它是否对你有帮助