Home Page Only Footer

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

Read More
<?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.

Related posts

Leave a Reply

4 comments

  1. 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 the end start of your if statement code

    Actually, it’ll be better to call it before as we can ensure the queries are reset

    <?php wp_reset_query();
    if ( is_home() ) { ?>
    text
    <?php }  ?>
    

    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?

    <p>
    <?php if ( is_home() ) { ?> 
    text 
    <?php } ?>
    <wp_reset_query()>
    <br />
    <br />
    

    The footer.php file should be located in wp-content/themes/nameofyourtheme folder

  2. 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:

    <?php
    function is_home(){
        $r = $_SERVER['REQUEST_URI'];
        return $r == '/' || $r == '' || $r == '/index.php';
    }
    
    if(is_home()) {
    ?>
    text
    <?php } ?>
    

    And where you want the footer, put:

    <?php include 'footer.php'; ?>
    

    instead of the line:

    <?php get_footer(); ?>
    

    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.

  3. 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.

  4. You need to modify the code to include a check for is_front_page() like so:

    <?php
        $ishomepage = ( is_home() || is_front_page() );
        switch( $ishomepage )
        {
            case true :
                echo 'Your homepage-only snippet of text goes here';
                break;
    
            case false :
            default :
                // Do nothing... or do something else...
                break;
        }
    
    ?>
    

    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.

    By default, WordPress shows your most recent posts on the front page
    of your site. But many WordPress users want to have a static front
    page or splash page as the front page instead. This “static front
    page” look is common for those who wish to not have a “blog” look to
    their site, giving it a more CMS (content management system) feel.

    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.