admin管理员组

文章数量:1426012

I want to create custom taxonomy conditional page. My post type is "laptops".

My current code dose not working. But this code work for post_type "post" section.

add_filter( 'template_include', 'mobile_laptop_category_page_template', 99 );
function mobile_laptop_category_page_template( $template ) {
    if ( wp_is_mobile() && is_taxonomy() && 'laptops' == get_post_type()) {
        $new_template = locate_template( array( '/mobile/category/taxonomy-routers.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }
    return $template;
}

I want to create custom taxonomy conditional page. My post type is "laptops".

My current code dose not working. But this code work for post_type "post" section.

add_filter( 'template_include', 'mobile_laptop_category_page_template', 99 );
function mobile_laptop_category_page_template( $template ) {
    if ( wp_is_mobile() && is_taxonomy() && 'laptops' == get_post_type()) {
        $new_template = locate_template( array( '/mobile/category/taxonomy-routers.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }
    return $template;
}
Share Improve this question edited May 25, 2019 at 16:28 fuxia 107k39 gold badges255 silver badges459 bronze badges asked May 25, 2019 at 14:19 Alal HossainAlal Hossain 1 3
  • What is a “custom taxonomy conditional page”? – Jacob Peattie Commented May 25, 2019 at 16:34
  • is_taxonomy is deprecated and it's not a conditional tag. Try using is_tax(). Refer to codex.wordpress/Function_Reference/is_tax. – filipecsweb Commented May 25, 2019 at 18:50
  • Thank You Filipecsweb. – Alal Hossain Commented May 28, 2019 at 14:08
Add a comment  | 

1 Answer 1

Reset to default 0

For custom taxonomy template you can create a php file in your child theme with name "taxonomy-[taxname].php for example taxonomy-laptops.php. This template will be use for any post type that contains taxonomy laptops. In taxonomy-laptops.php you could use a condtional like if post type is laptops then do something else something else.

I hope this could help you, i m a little confused with the querstion.

本文标签: How to Implement Custom Taxonomy Conditional Page