<?php
if ( is_page( '{enter your blog page slug here}' ) ) {
echo '<h1>{enter your blog page title here}</h1>';
} else {
echo '<h1>{enter your non-blog page title here}</h1>';
}
?>
0
您可以使用meta查询当前页面模板 . 您可以获取此元标记的当前页面模板:
_wp_page_template
完整代码:
if( get_post_meta($post->ID, '_wp_page_template', true) == "your-template.php" ){
// current page is created with your template
} else{
// other page template or defult template
}
0
假设您的博客页面有单独的模板,例如主题目录中的 blog.php .
那你应该按照下面的代码:
if ( is_page_template( 'blog.php' ) ) {
// Current Template is Blog
} else {
// Other Pages
}
3 回答
请使用以下代码而不是现在用于显示页面 Headers 的代码 .
您可以使用meta查询当前页面模板 . 您可以获取此元标记的当前页面模板:
完整代码:
假设您的博客页面有单独的模板,例如主题目录中的
blog.php
.那你应该按照下面的代码:
更多信息:http://codex.wordpress.org/Function_Reference/is_page_template
Update:
如果博客是WordPress中的一个页面,请按照以下代码:
如果这不起作用,那么您应该尝试使用
get_header
函数包含不同的头文件 .更多信息:http://codex.wordpress.org/Function_Reference/get_header
建议:我建议为您的博客页面创建新的页面模板,然后您就可以开始了 . 您可以参考this来创建新的页面模板并分配到页面 .