2012-04-03 66 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) 
)) 
); 

嘗試它幫助我,告訴它是否幫助你或不

相關問題