WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Limit if is_home / is_frontpage to the first page worth of posts (4 posts)

  1. matt_g
    Member
    Posted 5 years ago #

    Hi

    Is there a way to use if is_home or is_front_page to only return positive on the first page of results?

    I've got posts per page set to 5, but when I hit the "previous posts" link to go to the next page of results the is_home or is_frontpage is still giving me a positive result (showing the word "test").

    My code is:

    <?php if (is_home() ) { echo '<a>test</a>' ;} else { echo '<a href="[blog url]">home <span class="greydot">&bull;</span></a>' ;} ?>

    or

    <?php if (is_front_page() ) { echo '<a>test</a>' ;} else { echo '<a href="[blog url]">home <span class="greydot">&bull;</span></a>' ;} ?>

    thanks,
    mattg.

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Try <?php if(is_home() && !is_paged()) { [...] }?>

    In theory, that should only return TRUE, if you're on the first page.

    http://codex.wordpress.org/Conditional_Tags#A_Paged_Page

  3. matt_g
    Member
    Posted 5 years ago #

    Woot! all working. much appreciated :)

    cheers
    mattg.

  4. modus
    Member
    Posted 4 years ago #

    many thanks, just came in very handy

Topic Closed

This topic has been closed to new replies.

About this Topic