Custom Category Archive Pages

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.

Topic categories archives Wordpress

Category Web


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;
}

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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.