images_not_found

wordpress不同分类使用不同模板判断方法

<?php
   $term = get_queried_object();
    $beyond_slug = '';
    if(0==$term->parent){
        //没有上级 ,就是顶级分类,就用自己的别名判断
        $beyond_slug = $term->slug;
    }else{
        //这里说明不是顶级分类,那就是去找他的
        $category_parent = get_category($term->parent);
        $yr_slug = $category_parent->slug;
    }
    switch($beyond_slug){
        case 'news':
            get_template_part('template/news','');
            break;
        case 'case':
            get_template_part('template/case','');
            break;
//        case 'news':
//            get_template_part('template/1');
//            break;
//        case 'news':
//            get_template_part('template/1');
//            break;
    }

评论:(暂无)

留下评论

沧州网站建设