很抱歉我的noob代码,但它感觉很接近我想要实现的目标。我需要有关在存档后循环中显示分类法值的帮助。我有一个自定义的帖子类型,叫做;“播放”;还有与之相关的自定义分类法,称为;联盟“;和;系统;。有多种类型的“联盟”和“系统”,但我只需要显示每个帖子中的那些。代码如下:
<?php if( have_posts() ): while( have_posts() ): the_post();?>
<div class="row pick-row">
<div class="col-md-4 valign">
<div class="row">
<div class="col-md-6 col-6 pb-4">
<p class="pick-date"><b><?php the_field(\'date\');?></b></p>
<h2>
<?php the_title();?>
</h2>
</div>
<div class="col-md-6 col-6 pb-4">
<div class="model-league">
<p>
<b>Model</b>
</p>
<?php
// Get the taxonomy\'s terms
$terms = get_terms(
array(
\'taxonomy\' => \'system\',
\'hide_empty\' => true,
)
);
// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) { ?>
<a href="<?php echo esc_url( get_term_link( $term ) ) ?>">
<?php echo $term->name; ?>
</a><?php
}
}
?>
<p>
<b>League</b>
</p>
<?php
// Get the taxonomy\'s terms
$terms = get_terms(
array(
\'taxonomy\' => \'leagues\',
\'hide_empty\' => true,
)
);
// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) { ?>
<a href="<?php echo esc_url( get_term_link( $term ) ) ?>">
<?php echo $term->name; ?>
</a><?php
}
}
?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row picks-details">
<div class="col-md-3 col-6 pb-4">
<h2>
Selection
</h2>
<span>
<?php the_field(\'selection\');?>
</span>
</div>
<div class="col-md-3 col-6 pb-4">
<h2>
Odds
</h2>
<span>
<?php the_field(\'odds\');?>
</span>
</div>
<div class="col-md-3 col-6 pb-4">
<h2>
Stake
</h2>
<span>
<?php the_field(\'stake\');?>
</span>
</div>
<div class="col-md-3 col-6 pb-4">
<h2>
Units
</h2>
<span>
<?php the_field(\'units\');?>
</span>
</div>
</div>
</div>
<div class="col-md-2 pb-4 valign text-center text-md-right">
<a class="btn btn-main" href="<?php the_permalink();?>"">
Details
</a>
</div>
<div class="col-md-12">
<hr>
</div>
</div>
<?php endwhile; else: endif;?>
最合适的回答,由SO网友:Carina 整理而成
我又挖了一些,这个解决方案对我很有用,可以在归档页面中显示每个帖子的分类:
<?php echo get_the_term_list( $post->ID, ‘leagues’, ‘<li class=”tax_item”>’, ‘, ‘, ‘‘ ) ?>