事情是这样的,我用 get_post_type 函数创建了一个自定义分类法类型,然后自定义了文件的访问路径代码如下。
function tblog_chat_template( $template_path )
{
if ( get_post_type() == 'aichat' ) {
if ( is_single() )
{
$template_path = get_theme_file_path().'/chat/chat.php';
}
elseif(is_archive())
{
$template_path = get_theme_file_path().'/chat/chat-archives.php';
}
}
return $template_path;
}
add_filter( 'template_include', 'tblog_chat_template' );
结果,无论我如何通过链接,https://www.viphper.com/chat 访问时都不能跳到自己自定义的页面,于是查找资料,终于搞定。
解决办法
功能 get_post_type() 可以在循环外部使用,但需要可选参数($post_id) 要设置。
需要$post_id,我灵机一动,创建这个自定义的时候,没有添加文章,于是果断添加了一篇文章,于是乎奇迹就诞生了,然后就可以访问了。
原来我离成功的距离只差了一篇文章呀,真是服服的。




















评论抢沙发