Forums

Basic PHP Question (Pagination) (5 posts)

  1. nickaster
    Member
    Posted 4 months ago #

    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!

  2. Chip Bennett
    Member
    Posted 4 months ago #

    Try using the $paged global variable. e.g.:

    <?php
    global $paged;
    if ( $paged && '2' == $paged ) {
        // We're on Page 2;
        // do something
    }
    ?>
  3. nickaster
    Member
    Posted 4 months ago #

    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?

  4. Chip Bennett
    Member
    Posted 4 months ago #

    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
    }
    ?>
  5. nickaster
    Member
    Posted 4 months ago #

    Ah... easy, thanks!

Reply

You must log in to post.

About this Topic

Tags

No tags yet.