我在Word.php文件中的Word按下,我试图弄清楚如何使标题img只显示在主页上。我在代码中找到了该区域,并且尝试添加带有条件的if语句仅显示在该页面上。
if(is_front_page()){
require get_template_directory() . '/inc/custom-header.php';
}
答案 0 :(得分:0)
您需要使用is_home()
if(is_home()){
require get_template_directory() . '/inc/custom-header.php';
}
答案 1 :(得分:0)
你不能为主页制作不同的模板吗?
答案 2 :(得分:0)
如果您使用的是儿童主题,get_template_directory()
将返回父主题的路径。资料来源:http://codex.wordpress.org/Function_Reference/get_template_directory
因此,如果您没有为首页指定页面(即您的首页基本上是博客),is_home()
应该正常运行,否则请使用is_front_page()
。
如果您的文件(custom-header.php)位于正确的文件夹中,这应该可以解决问题:
if (is_front_page()) { // or is_home(), read above
include_once(get_bloginfo('stylesheet_directory') . '/inc/custom-header.php');
}