我正在创建一个wordpress主题,其中包含我附加到帖子的国家/地区的自定义字词
function awpt_countries_taxonomy() {
$labels = array(
'name' => _x( 'Country Name', 'taxonomy general name' ),
'singular_name' => _x( 'Country Name', 'taxonomy singular name' ),
'search_items' => __( 'Search for Country' ),
'popular_items' => __( 'Popular Countries' ),
'all_items' => __( 'All Countries' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Country Name' ),
'update_item' => __( 'Update Country Name' ),
'add_new_item' => __( 'Add New Country Name' ),
'new_item_name' => __( 'New Country Name' ),
'separate_items_with_commas' => __( 'Separate Country Names with commas' ),
'add_or_remove_items' => __( 'Add or remove Country' ),
'choose_from_most_used' => __( 'Choose from the most used Country Names' ),
'menu_name' => __( 'Country Names' ),
);
register_taxonomy('country','post',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'country' ),
));
}
add_action( 'init', 'awpt_countries_taxonomy', 0 );
这个功能运行正常,所以我在循环或single.php中显示任何帖子的国家名称,如下所示;
<?php
if( false != get_the_term_list( $post->ID, 'country' ) ) {
echo '<div class="country">';
echo '' . get_the_term_list($post->ID,'country', __( 'Countries', 'awpt' ), ' ', ' ', '' );
echo '</div>';
}
?>
我的tamplete和taxonomy-country.php也可以正常工作。
现在,我使用此plugin列出所有国家/地区列表,为每个字词添加图片
<?php foreach ($tax_terms as $cat) : ?>
<a href="<?php echo get_term_link($cat->slug, 'country'); ?>">
<img src="<?php echo z_taxonomy_image_url($cat->term_id,NULL, array(150, 190)); ?>" /> </a></div>
<a href="<?php echo get_term_link($cat->slug, 'country'); ?>">
<?php echo $cat->name; ?>
上面的代码列出了所有自定义术语作为类别,正如我之前所说,我可以在帖子或索引中显示国家名称get_the_term_list($post->ID,'country', __( 'Countries', 'awpt' ), ' ', '
,但我想只显示标志(图像)而不是索引上的名称在post的每个缩略图上。最好在循环上显示每个帖子的标志。非常感谢你帮助......