我需要显示与自定义Wordpress分类相关联的图标。分类法的代码是:
$labels = array(
'name' => 'Country/State/City' ,
'singular_name' => 'Genre' ,
'search_items' => __( 'Search Country/State/City' ),
'all_items' => __( 'All Country/State/City' ),
'parent_item' => __( 'Parent Country/State/City' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Country/State/City' ),
'update_item' => __( 'Update Country/State/City' ),
'add_new_item' => __( 'Add New Country/State/City' ),
'new_item_name' => __( 'New Country/State/City' ),
'menu_name' => __( 'Country/State/City' ), );
register_taxonomy( 'location', 'post', array( 'hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'rewrite' => true ) );
}
我在主题文件夹中创建了一个文件夹,其中包含国家标志(Spain.png,France.png等)
我需要显示一个包含最新帖子标题的列表,旁边有标记。
所以我认为我可以进行循环并获得一个帖子类别的最新10个帖子,显示它的标题,旁边的图标将是“path-to-image-folder / taxonomy-country” .PNG“
我不知道该怎么办...有人可以帮我一把手开始我吗?
修改
所以我得到了这个:
<h2>Recent Posts</h2>
<ul>
<?php
$args = array( 'numberposts' => '15' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
$terms = get_the_terms( $recent->ID, 'location' );
$flagimg='<img src="'.get_bloginfo('template_directory').'/images/flags/'.$terms[0]->slug.'.png" alt="'.$terms[0]->name.'" border="0" />';
echo '<li class="country-'.$terms[0]->slug.'"><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >'.$flagimg.' '.$recent["post_title"].'</a> </li> ';
}
?>
</ul>
但我得到的img src链接是:http://inovve.net/expoff/wp-content/themes/inovve/images/flags/.png
即缺少分类学名称....:/