admin管理员组文章数量:1323353
I have a Post template, when I select it in the Post options, it saves, but doesn't apply the template on the frontend. Any ideas why this is happening? The posts in question are in the default posts area.
Here is the start of my template file, which is interestingly titled as Casino Live Dealer Template Page Template in the theme editor. This insinuates to me that Wordpress is reading this as a page template.
<?php
/*
Template Name: Casino Live Dealer Template
Template Post Type: post
*/
I have a Post template, when I select it in the Post options, it saves, but doesn't apply the template on the frontend. Any ideas why this is happening? The posts in question are in the default posts area.
Here is the start of my template file, which is interestingly titled as Casino Live Dealer Template Page Template in the theme editor. This insinuates to me that Wordpress is reading this as a page template.
<?php
/*
Template Name: Casino Live Dealer Template
Template Post Type: post
*/
Share
Improve this question
asked Sep 9, 2020 at 10:21
Matt MaclennanMatt Maclennan
1111 bronze badge
1 Answer
Reset to default 0Fixed it! I have now created a single
folder in my theme's directory and put category specific templates in there. To enable this, I added this to the theme's function file
/*
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . '/single');
/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');
/**
* Single template function which will choose our template
*/
function my_single_template($single) {
global $wp_query, $post;
/**
* Checks for single template by category
* Check by category slug and ID
*/
foreach((array)get_the_category() as $cat) :
if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';
elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';
endforeach;
}
This was thanks to this article!
本文标签: Post template not applying on theme (potentially rendering as Page template)
版权声明:本文标题:Post template not applying on theme (potentially rendering as Page template) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742129487a2422092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论