投票结果为@supertrue,但想补充一些说明:
is_front_page() 打开时返回truesite front page (通常称为“主页”)is_front_page() 在站点首页上返回true,无论首页是否设置为显示Blog Posts Index 或astatic Page.is_home() 显示时返回trueBlog Posts Index.is_home() 显示博客文章索引时返回true,无论是在Front Page, 或在static Page.区分static Page 和Blog Posts Index 当出现在头版时get_option( \'show_on_front\' ), 返回page 或posts
EDIT
设置>>阅读设置为“您的最新帖子”,主页名称为索引。php位于主题目录中。
因此,根据我上面所说的:
打开时Front Page, 然后is_front_page() 始终返回true.当显示Blog Posts Index (“您最近的帖子”),is_home() 始终返回true.您的Front Page 设置为显示您的博客文章索引,因此both is_front_page() and is_home() 将返回true。
EDIT 2
所以最后一个问题是“有没有一种方法可以知道调用的函数是针对主页的?”(http://example.com/)而不是另一个?“”
对就是这样is_front_page() 用于。
如果您需要知道您位于首页,并且首页是静态的:
if ( is_front_page() && \'page\' == get_option( \'show_on_front\' ) )
如果你需要知道你在头版,头版是你的博客帖子:
if ( is_front_page() && \'posts\' == get_option( \'show_on_front\' ) )