簡體   English   中英

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

試試看對我有幫助,告訴它是否對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM