wordpress的页面判断都有函数可用,比如判断首页用,
<?php if(is_home()||is_front_page()){ /***********/ } ?>
如何判断自定义文章和分类法的页面呢?
<?php //判断是否为book文章类型的单页 if( is_singular('book') ){ /***********/ } /******判断是否为book文章类型的所有文章归档页********/ if( is_post_type_archive('book') ){ /********************/ } /***********判断是否为分类法country的分类页***************/ if( is_tax('country') ){ /****************/ } ?>
<?php //通过文章ID,分类法名称获取文章所属某分类法的信息 $terms = get_the_terms( $post->ID, 'country' ); if ( $terms && ! is_wp_error( $terms ) ) : $draught_links = array(); foreach ( $terms as $term ) { $draught_links[] = $term->name; } $on_draught = join( ", ", $draught_links );//用逗号分隔 echo $on_draught; endif; ?>
但是这个怎么输出的效果没有连接呢
<?php $terms = get_the_terms( $post->ID, 'country' ); if ( $terms && ! is_wp_error( $terms ) ) : $draught_links = array(); foreach ( $terms as $term ) { $draught_links[] = '<a href="'.get_term_link((int)$term->term_id,'mall').'">'.$term->name .'</a>'; } $on_draught = join( ", ", $draught_links ); echo $on_draught; endif; ?>