【发布时间】:2017-02-06 04:10:59
【问题描述】:
我已经尝试制作我的第一个 wordpress 主题,但我的博客的单页遇到了一些问题。 [我的博客页面][1]
这是我创建的自定义帖子类型,名为 blog_post。 奇怪的是,这似乎仅在它位于我的站点 ex 的子层上时才会发生。 {url}/blog_post/ 这里的页面看起来就像我的索引页面。
但在我的工作页面上,我的单个页面没有任何问题,并且它们的永久链接没有 {url}/work_post/ 附加到它们。 [我的工作页面][2]
我使用 functions.php 文件创建了我的单页的特殊样式
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';
/* <-------- if no single-cat page is found the return the single.php file
*/
elseif(file_exists(SINGLE_PATH . '/single.php'))
return SINGLE_PATH . '/single.php';
endforeach;
}
我希望有人能理解我的烂摊子:D
【问题讨论】:
标签: php wordpress custom-post-type