简体   繁体   English

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

[英]Display all posts from latest taxonomy in wordpress

I am creating a newspaper website that will have Volumes and Issues. 我正在创建一个报纸网站,其中有《卷》和《问题》。 Volumes increment yearly, issues increment weekly. 数量每年递增,问题每周递增。 I have created a custom post type of article with a taxonomy of issue. 我创建了具有问题分类的自定义文章类型的文章。

Currently the code below will get the most recent post from the article with the most recent issue taxonomy. 当前,下面的代码将从该文章中获取最新的文章,并包含最新的问题分类法。 I want it to get all of the posts from the most recent issue. 我希望它能获取最新一期的所有帖子。 I figured out I can get the next post by changing $issue[0]->slug to $issue[1]->slug. 我发现可以通过将$ issue [0]-> slug更改为$ issue [1]-> slug来获得下一篇文章。 I realize I just need a loop but I cant quite figure it out. 我意识到我只需要一个循环,但我无法弄清楚。

Your help is appreciated. 感谢您的帮助。

<?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'; ?>

You're not looping through your posts. 您不会浏览所有帖子。 You need to do something like: 您需要执行以下操作:

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

Thx for the answer @hohner.It really helped me to go ahead with my issue. 谢谢@hohner的回答。它确实帮助我解决了我的问题。 @Aaron Snyder for the complete result you can add some loop with your taxonomy information like this for showing all posts results @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)
))
);

Try it helped me and tell if it helped you or not 试试看对我有帮助,告诉它是否对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM