Forums

Static page and pagination - how to read page # from url (4 posts)

  1. paamayim
    Member
    Posted 3 years ago #

    Let's say I did a page:

    http://www.example.org/my-static/

    What I'd like to do is to make a browser of items in it and add pagination support.

    http://www.example.org/my-static/page/2
    http://www.example.org/my-static/page/3
    ... and so on.

    The question: how do I read the page numeber in PHP from inside the template page? If I was using ?page=1 I ould have used $_GET['page'] but how do I do in wordpress?

    Thanks.

  2. paamayim
    Member
    Posted 3 years ago #

    Well I think I found

    global $page;

    inside the plugin :|

  3. oneone11
    Member
    Posted 3 years ago #

    I had to do this once.. the way I ended up doing it was by placing the following PHP code in my theme...

    //grab the URL into a string variable (i.e., "yoursite.com/page/2" )
    $strURL = $_SERVER['REQUEST_URI'];
    //array the elements in the string btwn "/" (i.e. [page], [2] )
    $arrVals = split("/",$strURL);
    //boolean var used to alert when the integer page var is next
    $intnextone = 0;
    //integer variable for pagenumber
    $intpagenum = 0;
    // loop through the array
    foreach ($arrVals as $value) {
    	if ($intnextone == 1){$intpagenum=$value;} // assign var
    	if ($value == "page") {$intnextone =1;} //next loop is int
    }

    $intpagenum is your page number variable.

    Hope that helps

  4. paamayim
    Member
    Posted 3 years ago #

    Yeah that's the hard code way. By the way I found the method above that is working because WordPress itself already parse the number from the url, I suppose.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.