我试图仅根据分类词的标题来显示分类词的标题,而不是根据分类中列出的帖子。
目前,我的分类术语和单个帖子页面显示与每个帖子相关的所有分类标题。
例如......
我有一个名为' Residential'的分类法,其中包含与分类法相关的各种术语。这是一个链接:http://desrosiers.robertrhu.com/residential/
有一篇名为' West Shore'这与“住宅”中的两个分类术语相关联。分类,'装修'和'当代'
当我去当代'当代'或者' Renovations'术语页面或西海岸的#39;帖子,标题列出了两个分类术语作为标题。以下是一些链接:http://desrosiers.robertrhu.com/residential-category/contemporary/和http://desrosiers.robertrhu.com/residential/west-shore/
因此,如果我点击' Renovations',我希望该页面只显示标题' Renovations'。如果我点击' Contemporary',我希望该页面只显示' Contemporary'。如果我点击特定分类术语中的单个帖子,我希望该帖子显示帖子导航的分类术语标题。
提前感谢您的帮助!
以下是分类学术语存档页面的代码:
<?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(); ?>