| The code is as follows |
Copy Code |
<?php if (Is_home ()) {?> I will only show on the front page <?php}?> |
Is_home (); function returns a true when it is on the first page
The above code is commonly used only on the first page display
Insert any template page PHP can,
such as sidebar sidebar.php or footer footer.php
But if it had been preceded by a query_posts (); It's going to invalidate it.
The reason is that is_home is_virgin Is_ooxx this is_ prefix is based on the theme loop,
and Query_posts (); It's going to deviate from the main loop.
The solution is in is_home (); Before adding a wp_reset_query ();
| The code is as follows |
Copy Code |
<?php Wp_reset_query (); if (Is_home ()) {?> I will only show on the homepage, really! <?php}?> |
Second Kind
When you use the specified page as a page. In this case is_home () is not working.
You can use Is_front_page () to determine whether the current page is a specified homepage, and we need this function in the case described above.
| code is as follows |
copy code |
| <?php if (Is_home () | | | is_front_page ()) The Home page shows the code ................ <?php} |