在存档页面中,我尝试显示自定义分类法(称为位置)以及每个帖子标题、类别和标签。我无法让“get_the_terms”工作。
帖子标题、类别和标签工作正常。分类法不起作用。
<div class="post-listing">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<p><?php $tags = get_the_tags(); foreach($tags as $tag) { echo "$tag->name"; } ?></p>
<p><?php $terms = get_the_terms( 'locations' ); foreach($terms as $term) { echo "$term->name"; } ?></p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的functions.php 代码。
//hook into the init action and call create_locations_nonhierarchical_taxonomy when it fires
add_action( 'init', 'create_locations_nonhierarchical_taxonomy', 0 );
function create_locations_nonhierarchical_taxonomy() {
// Labels part for the GUI
$labels = array(
'name' …Run Code Online (Sandbox Code Playgroud)