Support » Fixing WordPress » Conditional statement didn't work as expected.

  • gulliver

    (@gulliver)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    gulliver

    (@gulliver)

    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.';}
    ?>

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional statement didn't work as expected.’ is closed to new replies.