我想在自定义的分类单元列表中显示图标,而不是分类单元名称,但只针对与图像相关的图标,如果没有图像,请显示分类单元名称。
我也安装了分类法图像插件,但它只添加图像,不替换分类法名称。tnx公司
这是我在存档{custom type}中的代码。php文件
<?php query_posts( array( \'post_type\' => \'custom_type\',\'posts_per_page\' => 20 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-md-3 clearfix"><div class="row"><article id="post-<?php the_ID(); ?>" <?php post_class( \'clearfix\' ); ?> role="article">
<?php // end article header ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<section class="entry-content" style="text-align:center;padding:20px;">
<div class="thumcap2"><?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(thumbnail);
}
?></a><a href="<?php the_permalink() ?>" class="title2" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
</section> <?php // end article section ?>
<footer class="article-footer" style="text-align:center;">
<?php
printf( __( \' %4$s\', \'bonestheme\' ), get_the_time( \'Y-m-j\' ), get_the_time( __( \'F jS, Y\', \'bonestheme\' )), bones_get_the_author_posts_link(), get_the_term_list( get_the_ID(), \'custom_cat\', \' \', \' | \', \'\' ) );
?>
</footer> <?php // end article footer ?>
</article></div></div> <?php // end article ?>
<?php endwhile; ?><div class="clearfix"></div>
SO网友:Maurizio
我在没有插件的情况下成功地修复了它,只是用taxonomz slug名称保存在主题图像路径pict中。png和此代码修改
<footer class="article-footer" style="text-align:center;">
<?php //$terms= apply_filters( \'taxonomy-images-list-the-terms\', \'\', array(\'taxonomy\' => \'custom_cat\',)); ?>
<?php //print_r( $terms); ?>
<?php $terms = get_the_terms( $post->ID, \'custom_cat\' );
$numcat=sizeof($terms);
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, \'custom_cat\' );
if( file_exists( TEMPLATEPATH .\'/images/\'. $term->slug .\'.png\') ){
?>
<a rel="tag" href="<?php echo $term_link; ?>"><img title="<?php echo $term->name; ?>" style="height: 21px; width: 21px;" src="<?php echo get_template_directory_uri() . \'/images/\' . $term->slug . \'.png\' ?>" alt="<?php echo $term->name; ?>"></a>|
<?php }else{ ?>
<a rel="tag" href="<?php echo $term_link; ?>"><?php echo $term->name; ?></a>|
<?php } }
//printf( __( \' %4$s\', \'bonestheme\' ), get_the_time( \'Y-m-j\' ), get_the_time( __( \'F jS, Y\', \'bonestheme\' )), bones_get_the_author_posts_link(), get_the_term_list( get_the_ID(), \'custom_cat\', \' \', \' | \', \'\' ) );
?>
</footer> <?php // end article footer ?>