我试图仅根据分类术语的标题来显示分类术语的标题,而不是基于分类中列出的帖子。
目前,我的分类术语和单个帖子页面正在显示与每个帖子相关的所有分类的标题。
例如...
我有一个名为“住宅”的分类法,其中包含与该分类法相关的各种术语。这是一个链接:http ://desrosiers.robertrhu.com/residential/
有一个名为“West Shore”的帖子与“住宅”分类中的两个分类术语“装修”和“当代”相关联。
当我转到“当代”或“装修”术语页面或“西岸”帖子时,标题将两个分类术语列为标题。以下是一些链接:http ://desrosiers.robertrhu.com/residential-category/contemporary/和http://desrosiers.robertrhu.com/residential/west-shore/
因此,如果我单击“装修”,我希望该页面仅显示“装修”标题。如果我点击“当代”,我希望该页面只显示“当代”。如果我单击特定分类术语中的单个帖子,我希望该单个帖子显示导航该帖子的分类术语标题。
在此先感谢您的帮助!
这是分类术语存档页面的代码:
<?php
/*
* Template Name: Residential Category Template
* Description: Template for Residential Project Types archive
*/
get_header(); ?>
<div id="main-content">
<?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>
<!--Residential Taxonomy Header-->
<div id="residential-heading-single"
class="heading property-heading hide-for-small show-for-medium">
<h3 style="border-right: none; padding-left: 0;">
<a href="<?php bloginfo('url'); ?>/residential/">
Residential
</a>
</h3>
<h1>
<?php
$terms = get_the_terms( get_the_ID(), 'residential_project_types' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
echo $term->name;
}
}
?>
</h1>
</div>
<?php $terms = get_terms( array(
'taxonomy' => 'residential_project_types',
'orderby' => 'count',
'hide_empty' => true
) );
foreach( $terms as $term ) :
?>
<a class="property-thumb-link"
href="<?php echo get_term_link( $term ); ?>">
<div class="property-thumb column medium-6 small-12">
<img src="<?php the_field('category_image', $term); ?>"
alt="<?php the_field ('category_image_alt', $term); ?>" />
<div class="property-thumb-title">
<h2>
<?php echo $term->name; ?>
</h2>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php get_footer(); ?>
这是单页的代码:
<?php
/*
* Template Name: Residential Single Template
* Description: Template for Residential Project Types single
*/
get_header(); ?>
<div id="main-content">
<?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>
<!--Residential Single Header-->
<div id="residential-heading-single"
class="heading property-heading hide-for-small show-for-medium">
<h3>
<a href="<?php bloginfo('url'); ?>/residential/">
Residential
</a>
</h3>
<h3>
<?php
$terms = get_the_terms( get_the_ID(),
'residential_project_types' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
echo '<a href="' .esc_url( $term_link ) . '">' .
$term->name . '</a>';
}
}
?>
</h3>
<h1><?php the_field('project_title'); ?></h1>
</div>
<?php $terms = get_terms( array(
'taxonomy' => 'residential_project_types',
'orderby' => 'count',
'hide_empty' => true
) );
foreach( $terms as $term ) :
?>
<a class="property-thumb-link"
href="<?php echo get_term_link( $term ); ?>">
<div class="property-thumb column medium-6 small-12">
<img src="<?php the_field('category_image', $term); ?>"
alt="<?php the_field ('category_image_alt', $term); ?>" />
<div class="property-thumb-title">
<h2>
<?php echo $term->name; ?>
</h2>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php get_footer(); ?>