2012-04-03 125 views
0

我正在创建一个报纸网站,其中包含卷和问题。卷每年递增,每周发布增量。我创建了具有问题分类的自定义帖子类型的文章。显示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'; ?> 

回答

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; 
+0

我有一个类似的,而循环 - 尽管该分类法中至少有5个结果,但它只能得到1个结果。任何其他想法? – 2012-04-03 19:07:56

+0

也许摆脱所有其他搜索条件,只是使用'query_posts('issue ='。$ latest_edition);' – hohner 2012-04-03 19:29:42

+0

我认为这个问题是开始post_type与& - 无论哪种方式,玩弄该查询字符串导致工作参数和快乐的程序员!感谢芽! – 2012-04-03 19:58:16

0

Thx为答案@ hohner.It真的帮助我继续我的问题。 @Aaron斯奈德为完整的结果,你可以像这样与你的分类信息添加一些循环用于显示所有帖子引起

$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) 
)) 
); 

尝试它帮助我,告诉它是否帮助你或不

相关问题