WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_front_page works in header, not footer (8 posts)

  1. swissmiss07
    Member
    Posted 5 years ago #

    I am trying to vary the formatting of my pages based on whether it is the front/home page. I am using an IF statement with the is_front_page() function to determine which image to show.

    This is working fine in header.php, but footer.php will never return TRUE for the is_front_page function. Somehow, the value for is_front_page() is being changed between the header and footer includes.

    Does anyone know what might be causing this? I'm a WordPress newbie, and inherited this site from someone else, so ANY help/guidance you can give will be greatly appreciated.

    Thanks!

  2. s_ha_dum
    Member
    Posted 5 years ago #

    What does you front page template look like?

  3. swissmiss07
    Member
    Posted 5 years ago #

    The site is http://www.dmrins.com/. If you to the left and right of the brown stripe - just below the stock photos - you will see two short horizontal white lines. These should not appear on the other pages of the site. If you go to any other page on the site, you will see that they have been removed from the left side (which is controlled by header.php), but they still exist on the right side (which is controlled by footer.php)

    If you view source on the home page, you will see some comments dated 2/26/09 and referring to FP. The first comment is generated by header.php. The second one is generated by index.php, and the third is generated by footer.php. They all use the same if statement if (is_front_page()){echo ...} Somehow, is_front_page returns true in header.php and changes to false in index and footer.php.

    Thanks,
    Julie

  4. s_ha_dum
    Member
    Posted 5 years ago #

    It looks like you are loading the wrong image-- margin-rt.jpg instead of margin-rt2.jpg. Switching those images, I assume, is what the is_home_page() switch does. Right?

    is_front_page() doesn't work like you describe on my site so something is resetting that value, as you suspected. I first thought you could just move the troublesome switch to the header.php but since you are all tables you can't. You are locked in. Without seeing your raw php I can't tell you what is changing that value. My blind guess is that something in the page is resetting the $post array.

    However, probably the easiest thing to do is to set a variable in the header, where is_front_page() is working for you. Set, for example, $myhomepage = is_front_page(); Then, from then on, don't switch on is_home_page(), switch on $myhomepage instead. Try that and let me know.

  5. t31os
    Member
    Posted 5 years ago #

    I'd suggest the same as apljdi storing the is_front_page/is_home as a variable then checking the varible...

  6. swissmiss07
    Member
    Posted 5 years ago #

    Thanks, aplijdi.

    I tried a variation of your suggestion and the site is working fine now. I had to define the $myhomepage variable in index.php before it called get_header(). Then, I had to declare it as global inside the footer.php file (makes since, since that is called inside of a function).

    Thanks again for your help!

  7. agenerousdesigner
    Member
    Posted 5 years ago #

    I had the same problem. Check out my comment in another forum post about the same problem. I used wp_reset_query() and there's no need for a global variable.

  8. scripty
    Member
    Posted 5 years ago #

    wp_reset_query() did the job for me with a similar problem as described above. Just wanted to say thanks!! Hadn't known about that one before. :D

Topic Closed

This topic has been closed to new replies.

About this Topic