• Hi there. I have a pretty standard wordpress front page with pagination at the bottom so I can go to page 1, 2, … to infinity.

    All the pages look pretty much the same.

    How can I put a switch on certain pages to do something different? IN other words:

    “If this is page 2, show this bunch of HTML” .. or “If this is not page 3-infinity” then put the word “FOO” in this location.

    Might someone know the basic PHP do to that?

    THANKS!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try using the $paged global variable. e.g.:

    <?php
    global $paged;
    if ( $paged && '2' == $paged ) {
        // We're on Page 2;
        // do something
    }
    ?>
    Thread Starter nickaster

    (@nickaster)

    Thanks …

    Dumb question perhaps, but what are the // for? That means a comment inside php right? If I try to put HTML there it kills the whole page, what’s the right way to code HTML in that area?

    If I try to put HTML there it kills the whole page, what’s the right way to code HTML in that area?

    You have to close the PHP tag, add your HTML, then open a new PHP tag:

    <?php
    global $paged;
    if ( $paged && '2' == $paged ) {
        // We're on Page 2;
        // do something
        ?>
        <!-- HTML GOES HERE! -->
        <?php
    }
    ?>
    Thread Starter nickaster

    (@nickaster)

    Ah… easy, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Basic PHP Question (Pagination)’ is closed to new replies.