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

时间:2012-04-03 15:12:08

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

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

目前,下面的代码将从带有最新问题分类的文章中获取最新帖子。我希望它能够获得最新一期的所有帖子。我想通过将$ 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'; ?>

2 个答案:

答案 0 :(得分:3)

您没有在帖子中循环播放。您需要执行以下操作:

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

答案 1 :(得分:0)

答案是@ hohner.It真的帮助我继续解决我的问题。 @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)
))
);

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

相关问题