WordPress.org

Ready to get started?Download WordPress

Forums

Conditional statement didn't work as expected. (4 posts)

  1. gulliver
    Member
    Posted 2 years ago #

    I want to display text on the first page of my posts, and different text on subsequent pages. I have a static front page, with posts at 'clips'.

    I thought I'd be ok in adding this to home.php:

    <?php
    if (! is_home() && !is_paged())
    {echo 'Text for first page.';}
    else
    {echo 'Text for subsequent pages.';}
    ?>

    But it doesn't work (the text for subsequent pages also appears on the first page). So, to get it to do what I wanted, I re-coded as:

    <?php
    if (! is_page('clips') && !is_paged())
    {echo 'Text for first page.';}
    else
    {echo 'Text for subsequent pages.';}
    ?>

    I'm wondering why the is_home statement didn't work.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

  3. gulliver
    Member
    Posted 2 years ago #

    Thanks.

    I'd read that page a lot before posting, and on a re-look still don't understand why the 'is_home' doesn't apply the required treatment - because the page is 'the main blog page' and seems to meet the 'so if you've set a static page for the Front Page, then this will only be true on the page which you set as the "Posts page"' requirement.

    And, I'm even more confused that 'is_front_page() ' does work - as the 'clips' page on which blog content is posted clearly doesn't meet the 'the front of the site is displayed' requirement.

    Having thought more about this, I've recoded to something simpler - because the original code was used in an index.php template, in a theme which didn't have a home.php, and hence needed the 'is_home' condition.

    I since realised that now I've added a home.php template and have a static front page (which uses a front-page.php template), home.php is only used to deliver the blog content pages and so doesn't need any 'is_' condition and hence the requirement for different code on subsequent pages can be covered thus:

    <?php
    if ( $paged < 2 ) {echo 'Text for first page.';}
    else {echo 'Text for subsequent pages.';}
    ?>
  4. tanzdare2002
    Member
    Posted 1 year ago #

    This is my site:
    http://adreamerschase.com/the-drive/

    There are road sign icon signifying each post category. Now, i need to put a road sign at the bottom of each post..under the "Posted in..."

    Please help me with this. Really need badly.

    By the way, here is a screenshot of the task i need to get done.

    http://awesomescreenshot.com/077xpo751

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.