function cat_slug(){
$cat = get_query_var('cat');
$yourcat = get_category($cat);
return $yourcat->slug;
}
$category = get_the_category(); echo ‘cat-‘.$category[0]->slug;
category子父母模板
子模板与父级模板相同
function category_template($template){ $category = get_queried_object(); if($category->parent !='0'){ while($category->parent !='0'){ $category = get_category($category->parent); } } $templates = array(); if ( $category ) { $templates[] = "category-{$category->slug}.php"; $templates[] = "category-{$category->term_id}.php"; } $templates[] = 'category.php'; return locate_template( $templates ); } add_filter('category_template', 'category_template');
子模板与父级模板不同
function get_category_parent($parent) { global $cat; $parent=get_category($cat); if($parent->parent)return ture; else return false; }
data-client用法
<body <?php body_class(); ?> data-XXX="<?php if(wp_is_mobile()){ echo 'example';} ?>"></body> body[data-XXX=example] { css: }