Show something only on index page (10 posts)

  1. wcp
    Posted 9 years ago #

    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?

  2. moshu
    Posted 9 years ago #

    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.

  3. wcp
    Posted 9 years ago #

    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:

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

  4. wcp
    Posted 9 years ago #

    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!

  5. moshu
    Posted 9 years ago #

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

  6. wcp
    Posted 9 years ago #

    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.

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

  8. moshu
    Posted 9 years ago #

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

  9. wcp
    Posted 9 years ago #

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

  10. Cadoc
    Posted 9 years ago #

    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.

        if (is_page('Home'))
             echo 'Home returned true';
             echo 'Home returned false';

    Works well.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.