我有自己的 post_type “服务”,它有自己的分类“服务类别”。好吧,因此,这个 post_type 中的条目是按标题分布的,只有在每个标题中都有一个与标题对应的帖子。例如,有一个标题“kt”,它有描述、图片、名称,这个标题包含条目“kt”,以及其他条目。
在 /services 页面上,我需要显示“服务类别”中所有类别的列表,而不是它们的描述等条目,以及与此类别相关的所有条目的列表
我试图通过get_categories在archive-services.php中显示类别,一切都显示了,但是切换到特定类别后,single.php被连接,并且在某些page.php上
如何正确实施这个想法?
<?
$categories = get_terms( array(
'taxonomy' => array( 'services-category' ), // название таксономии с WP 4.5
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
) );
if( $categories ):
foreach( $categories as $cat ):
$image_id = get_term_meta( $cat->term_id, '_thumbnail_id', 1 );
$image_url = wp_get_attachment_image_url( $image_id, 'full' );
?>
<div class="col2">
<div class="service">
<div class="preview">
<img src="<?= $image_url ?>">
</div>
<div class="description box">
<h2><a href="<?= get_term_link($cat) ?>"><?= $cat->name?></a></h2>
<p><?= $cat->description?></p>
</div>
</div>
</div>
<?endforeach;
endif;
?>
如果你想要一个与分类具有相同标签的页面,我认为你需要这样的东西。
在分类模板中,您可以获取其标签并按标签选择相应的帖子