• Resolved sp00f

    (@sp00f)


    im trying to add to my index.php a code that if its the front page of the site, it will do something, and if its not(regular page) it will do something else.

    iv’e tried this code`
    <?php
    if ( is_front_page() ) {
    blabla home
    } else {
    bla bla data
    }
    ?>
    `

    but its not working ! i read every post about this issue and still no luck ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • MichaelH

    (@michaelh)

    From Conditional Tags

    The Main Page

    is_home()
    When the main blog page is being displayed. (WordPress 2.1 handles this function differently than prior versions. See Alternate Methods for Setting the Front Page for pre-2.1 WP.)

    Note: If you select a static Page as your frontpage (see below), this tag will be applied to your “posts page”.
    [edit] The Front Page

    is_front_page()
    When it is the front of the site displayed, whether it is posts or a Page. 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 ‘Settings > Reading ->Front page displays’ is set to “A static page” and the “Front Page” value is the current Page being displayed. Note: this tag was added at Version 2.5.

    Thread Starter sp00f

    (@sp00f)

    so basiclly how can i do this ?
    1 page, index.php, and if its front page some html code and if its not front page then all pages will get some other html.
    thats why im trying to do dunno what to use im abit confused

    Devin Price

    (@downstairsdev)

    WordPress uses different templates for pages on your site. If you have a page.php template in your theme, that will be used to display your pages. If you have a single.php, that will be used to display your single posts. index.php or home.php would display your home page, or page.php if you have a certain page selected as the home page through the reading options.

    So, your conditional statement:

    <?php if (is_front_page()){ ?>
        <p>Home Page</p>
      <?php else { ?>
         <p>Not Home Page</p>
      <?php } ?>
    ?>

    Would only really be useful in the header.php or the footer.php file- or in page.php if you have a certain page selected in the reading options.

    Thread Starter sp00f

    (@sp00f)

    but if i use home.php as my main page i have to make in options > reading first page view as “last posts” and then my first page will be a post and not a page so home.php is not really helping me, or there is a way to make home.php to be viewed by a normal page and not by pots only.
    thanks agian.

    Dear Moderator i think there where different kind to solve this problem.

    Try this in any php – header.php,index.php,page.php,single.php

    Example:

    <?php
    if (is_front_page())
    {?>
    
    <div>Flash Gordon</div>
    
    <?php } else { ?>
    
    <div>Wins the Battle!</div>
    <?php } ?>

    is_home fixed my problem, strange though I swear is_front_page worked previously, maybe something got changed

    kureikain

    (@kureikain)

    It maybe you use new menu system and add Home as a menu item, correct?
    If so, is_front_page() will stop working

    kureikain

    (@kureikain)

    Or use is_nav_menu_item() to find out “home” menu item

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘if is_front_page not working’ is closed to new replies.