简体   繁体   English

Wordpress:使用静态首页时像is_blog_index()之类的东西吗?

[英]Wordpress: Something like is_blog_index() when using a static front page?

In WordPress 3 I've set up a static front page (called "Home"). 在WordPress 3中,我设置了静态首页(称为“首页”)。 I need to add a condition in my common header that will return true when viewing the main blog page. 我需要在我的通用标头中添加一个条件,该条件在查看博客主页面时将返回true。 The built-in function is_page('blog') doesn't work for this, is_front_page() doesn't either and is_home() returns true on Home as expected. 内置函数is_page('blog')对此不起作用,is_front_page()也不起作用,并且is_home()在Home上按预期返回true。 I could have sworn WP already had a function for determining if we're on the blog index, but I can't find it anywhere. 我本可以宣誓就职的WP已经具有确定我们是否在博客索引中的功能,但是我在任何地方都找不到它。 Is there one, or do I need to write a custom function? 有一个,还是我需要编写一个自定义函数?

the funcation is is_front_page() to use for your static front page, and is_home() to use for your recent posts page. 函数is_front_page()用于静态首页,而is_home()用于最近的帖子页面。 you must be doing something wrong. 你一定做错了。

Take care about the queries you're running before testing on what page you are, because they can modify the standard one for the instance. 在对当前页面进行测试之前,请注意您正在运行的查询,因为它们可以修改实例的标准查询。

To ensure you'll get the desired page, do a wp_reset_query() just before the is_home() , or is_page() test. 为了保证你会得到想要的网页,做一个wp_reset_query()就在之前is_home()is_page()测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM