【发布时间】:2025-12-28 12:20:08
【问题描述】:
我创建了一个名为“教育”的自定义帖子类型。使用这种自定义帖子类型,我制作了一个名为“Years”的自定义分类法。假设我要以这种格式为此自定义帖子类型添加大约 10 个帖子:
title of custom post type (Education), Custom Taxonomy Name (Year)
如何在我的页面上按顺序显示帖子的标题和分类名称?
(像这样)
Vimy College 2014
Albatross 2013
Some College 2011
Another College 2010
...
...
到目前为止,这是我页面的代码:
<?php /* Template Name: Education Page */
get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div>
<?php
// The args here might be constructed wrong
$args = array( 'post_type' => 'education',
'terms' => 'years',
'orderby' => 'terms',
'order' => 'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<h3>';
the_title();
echo '</h3>';
// I don't know what else to put here to display the associated taxonomy name
// (and in sequential order)
endwhile;
?>
</div>
<?php endwhile; endif; ?>
所以澄清一下,第一个 have_posts() 循环只是回显实际页面,内部循环应该生成上述格式以列出帖子标题,但按自定义分类名称排序(在这种情况下,数字)。
【问题讨论】:
标签: php wordpress custom-post-type custom-taxonomy