我在网站上创建了自定义帖子类型和分类法,但是当我查看分类法页面时,它显示了错误的页面标题。不是在标题上显示“ Taxonomy Term Name”,而是在该页面上显示第一篇文章的标题?
这是我的分类页面模板...
<div class="one-whole">
<!-- Course Tax -->
<?php
// Get the taxonomy
$taxonomy = get_queried_object();
$id = $taxonomy->term_id;
$name = $taxonomy->name;
$slug = $taxonomy->slug;
?>
<h1><?php echo $name; ?> Training Courses</h1>
<?php echo term_description( $id, $name ) ?>
<hr>
<section class="flexbox one-whole">
<?php // Create a custom loop for all items in this taxonomy
$args = array(
'post_type' => 'htl_training',
'posts_per_page' => -1,
'order' => 'asc',
'orderby' => 'name',
'tax_query' => array ( array(
'taxonomy' => 'course-categories',
'terms' => $taxonomy->slug, // Taxonomy Term to Search in
'field' => 'slug',
'operator' => 'IN')
)
);
$posts = new WP_Query($args);
if($posts->have_posts()) :
while($posts->have_posts()) :
$posts->the_post(); ?>
<!-- Card -->
<div class="card card-title-below">
<?php $image = get_field('accrediting_body'); ?>
<?php if( !empty($image) ){ ?>
<?php
// check if the repeater field has rows of data
if( have_rows('endorsing_bodies','options') ){
// loop through the rows of data
while ( have_rows('endorsing_bodies','options') ) {
the_row();
$hook = get_sub_field('logo_hook', 'options');
$icon = get_sub_field('logo','options');
$accrediting_body = get_field('accrediting_body');
if( $accrediting_body ){ ?>
<div class="training-provider">
<?php if( $accrediting_body === $hook ) {
echo '<img src="' . $icon['url'] . '" alt="' . $hook .'" />';
} ?>
</div>
<?php
}
}
} else { } ?>
<?php } ?>
<a href="<?php the_permalink(); ?>" class="non-animated-link">
<?php htl_the_post_thumbnail(); ?>
</a>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
</div><!--/ Card -->
<?php
endwhile;
else:
echo' Oops, there are no posts';
endif;
?>
<?php wp_reset_postdata(); ?>
</section>
<!-- Course Tax -->
</div>
如何显示分类学术语名称作为页面标题?