I have a blog, http://sweatingthebigstuff.com and I would like to add an extra line in the footer which will display only from the homepage. I found this code, but it is not working for me. Do I have the wrong syntax or is there something else I can try to get this to work?
<?php if ( is_home() ) { ?>
text
<?php } ?>
Here is where footer.php is called
<?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
<div class="cleared"></div>
<?php get_footer(); ?>
And here is the footer code:
text 2
Contact | Disclaimer | Privacy Statement
Copyright © 2009-2010 Sweating The Big Stuff. All Rights Reserved.
and then some sitemeter crap.
is_home()
sets a global var that doesn’t seem to reset itself or re-evaluate, wp kinda strange.Try putting
wp_reset_query()
at theendstart of your if statement codeActually, it’ll be better to call it before as we can ensure the queries are reset
Now that the php is working, ideally you’d want the code above.
text
I just did a view source and I can plainly see the php code, which shouldn’t be visible since it is meant to be parsed server side. The following shouldn’t be there in the view source…. wrong file being edited?
The footer.php file should be located in wp-content/themes/nameofyourtheme folder
is_home()
is a method that should return true or false. You need to implement this method somewhere. If blogspot doesn’t implement this method for you, you need to do it yourself. For your website I think this function would do what you want:And where you want the footer, put:
instead of the line:
I believe your problem is that get_footer() is reading the footer as text, so it isn’t executing the PHP beforehand. If you do it this way you can add as much PHP in the header as you want.
There is nothing wrong with your syntax, and when I view your page source, I see ” text “
What is the file extension of your footer page? if it is “footer.php” then I shouldn’t see the opening and closing terms for php (). php won’t run unless the file extension is “.php”
as to a previous answer:
<?php wp_reset_query();?>
should go BEFORE<?php if(is_home()){?>text<?php } ?>
in this scenario. is_home() depends on a loop being present on the page. Maybe somewhere you used a custom query, or one of your plugins used a custom query that upset the default query vars. Like I said, use the reset statement before your if statement.You need to modify the code to include a check for
is_front_page()
like so:Reference: WordPress Codex: is_front_page()
Default WP installations don’t have a homepage defined, it uses your index.php and checks for other templates like a
home.php
template as a starting point (home.php
only if your theme has it.) Here’s a diagram from their online docs that shows how their hierarchy works: WordPress Template Hierarchy.If you want to know how to set a static homepage, read this article and follow the instructions: Creating a Static Frontpage. When you set a static front page,
is_home()
will work as expected.