admin管理员组

文章数量:1122846

I have a WP installation with 6 categories and I want 3 of them to use a custom Category Archive Page called "category-special.php" (default page is the "category.php"). I found the code below that looks to be close to my query, how can I modify and make it work for me, so categories 31,40 and 55 to load the above specific page?

add_filter( 'template_include', 'wpsites_photo_page_template', 99 );
function wpsites_photo_page_template( $template ) {
    if ( is_category('33') ) {
        $new_template = locate_template( array( 'photo.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }
    return $template;
}

Thank you.

I have a WP installation with 6 categories and I want 3 of them to use a custom Category Archive Page called "category-special.php" (default page is the "category.php"). I found the code below that looks to be close to my query, how can I modify and make it work for me, so categories 31,40 and 55 to load the above specific page?

add_filter( 'template_include', 'wpsites_photo_page_template', 99 );
function wpsites_photo_page_template( $template ) {
    if ( is_category('33') ) {
        $new_template = locate_template( array( 'photo.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }
    return $template;
}

Thank you.

Share Improve this question edited Jul 9, 2017 at 13:23 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jul 9, 2017 at 7:02 geoplousgeoplous 1071 silver badge6 bronze badges 2
  • check below thread<br> wordpress.stackexchange.com/questions/168754/… – Roshan Deshapriya Commented Jul 9, 2017 at 8:12
  • well I want to have different template for the category archive page ONLY not for the pages under the category – geoplous Commented Jul 9, 2017 at 8:38
Add a comment  | 

2 Answers 2

Reset to default 0

you can use the category-slug.php file name if you want to have a custom page for each category

https://codex.wordpress.org/Category_Templates here is a link that will help you.

try bellow code :

add_filter( 'template_include', 'wpsites_photo_page_template', 99 );
function wpsites_photo_page_template( $template ) {
    if ( is_category('31') || is_category('40') || is_category('55') ) {
        $new_template = locate_template( array( 'photo.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }
    return $template;
}

本文标签: categoriesCustom Category Archive Pages