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
2 Answers
Reset to default 0you 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
版权声明:本文标题:categories - Custom Category Archive Pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295004a1929478.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论