wordpress 输出指定分类 创建分类菜单导航

在列表页输出指定分类法的terms菜单 

/**
 * 在列表页输出指定分类法的terms菜单
 * 默认输出一级类别,可指定父分类id
 *
 * $tax:	the taxonomy
 * $parent: default as 0
 * $loop_temp: 	选填单项模版id,不填直接输出链接
 * 				模版项中使用变量:$term, $term_link
 */
function x_show_tax_terms( $tax, $parent=0, $loop_temp ) {
	$args = array(
		'taxonomy'		=>	$tax,
		'hide_empty'	=> 	false,
		'parent'		=>	$parent
	);
	
	$terms = get_terms($args);
	$term_now = get_queried_object()->term_id;
	if(is_array($terms)){
		foreach ($terms as $term) {
			$term_link = get_term_link($term->term_id, $tax);
			if(!$loop_temp){
				echo ' ';			
			}else{
				include get_theme_file_path( 'template-parts/loop-'.$loop_temp.'.php' );
			}
		}
	}
}

你可能感兴趣的:(Wordpress,php)