• Hi
    I thought this code would show things only on the index page:

    <?php if ( is_home() ) { ?>
    Here the content only on the index page
    <?php } ?>

    But this keeps showing the content on the ‘next page’ pages too… I strictly want to show it only on the index page. Is there a quick code like the one above for that?

Viewing 9 replies - 1 through 9 (of 9 total)
  • If you mean the “next/prev posts” – that’s your index, too!
    Only not showing 999 posts, only the number set in your Options > Reading.

    The Codex is down atm but I remember something is_paged (or similar, I am not a coder!) and that is referring exactly to your situation.

    Thread Starter wcp

    (@wcp)

    yea seems the is_paged has to do with it im now looking at http://codex.wordpress.org/Conditional_Tags

    As i said i only want something to show in the index page, i mean like this:
    domain.com/index.php

    I know they call the the next/prev post pages also the ‘front page’ but it isn’t the index page since every site has only one main index page. The next/prev post pages look like this:
    domain.com/page/2/index.php
    So these are not the main index page.

    im now looking into the conditional tags page to see if i can find anything i can use.

    Thread Starter wcp

    (@wcp)

    I thought a combination code with is_home and is_paged would work but im not a php guy… on the paged pages it just shows the home text too… somebody help!

    I am not a coder either, but the “combination” should tell WP to display your text when it is home but is NOT paged.

    Thread Starter wcp

    (@wcp)

    moshu, thanks alot for the pointer man, i found it 🙂
    it seems that the ‘exclude’ command after the ‘if’ command is ‘&&!’, so this is the code I used:

    <?php if ( (is_home())&&!(is_paged()) ){ ?>
    <h1>Welcome to my site, etc. etc.</h1>
    <?php } ?>

    And it works perfectly. Reminder for others looking for the same: Check the extra set brackets around ‘is home but not is paged’ part, those are mandatory for it to work.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    This should work just as well. Bit simpler.
    if (is_home() && !is_paged())

    It’s not an “exclude”. It’s an “AND” and a “NOT”. Boolean logic.

    I think the correct way to say it is
    && = AND
    ! = NOT

    Thread Starter wcp

    (@wcp)

    yea you’re both right, & otto that simplified code does indeed work like a charm too.
    Thanks.

    I’m using WP v2.1.2 and the conditional is_home no longer works for v2.1 and above. More info is here

    I have my a static page called Home, which I set as my front page and I’ve put the code below inside the body element on my index page.

    <?php
        if (is_page('Home'))
        {
             echo 'Home returned true';
        }
        else
        {
             echo 'Home returned false';
        }
        ?>

    Works well.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show something only on index page’ is closed to new replies.