Wordpress function is_front_page() not working
I have a "static" page set up as my front page for Wordpress.
I have this in the index.php file:
<?php
if (is_front_page() || is_home()) {
?><p>TEST FRONT PAGE</p>
<?php
} ?>
For some reason, the "TEST FRONT PAGE" does not show up on the front page, but does show up on the posts page (as it shoul开发者_运维问答d, for these purposes only)...I'm using Wordpress 3.0, and I tested this on the twentyten template itself!
Anyone know why?
Thanks, Amit
Because the front page is loading from front-page.php not index.php.
EDIT
It's loading from page.php. You can read more about the template hierarchy here:
http://codex.wordpress.org/Template_Hierarchy
The is_home()
tag actually looks for the page where all your recent posts are shown. If you are on the homepage and you are showing recent posts there, is_home()
will return true. And if your front page is set static or template, is_home()
will return false but will return true for any inner page where your recent posts are being shown.
The is_front_page()
It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page
displays is set to "Your latest posts",
or when is set to "A static page" and the "Front Page" value is the current Page being displayed.
References
Here's Difference between is_home() and is_front_page()! And a reference to Codex Conditional Tags
Putting <?php wp_reset_query(); ?>
before the if(is_front_page() || is_home()){}
worked witht he same issue i was having
精彩评论