Samik Chattopadhyay
Samik Chattopadhyay

Reputation: 1850

wordpress pagination get current page number from url

I need to extract the value of "page" i.e 5 from this url - http://snypher.local/photos/page/5 What should I do to extract it in Wordpress? I am not able to get it from the $_GET super global.

Upvotes: 12

Views: 26626

Answers (4)

Samik Chattopadhyay
Samik Chattopadhyay

Reputation: 1850

function get_url_var($name)
{
    $strURL = $_SERVER['REQUEST_URI'];
    $arrVals = explode("/",$strURL);
    $found = 0;
    foreach ($arrVals as $index => $value) 
    {
        if($value == $name) $found = $index;
    }
    $place = $found + 1;
    return $arrVals[$place];
}

$page = get_url_var('page');

I have used this function to get the value of the variable page from the url.

Upvotes: 7

Rameez SOOMRO
Rameez SOOMRO

Reputation: 1539

its work fine i've tested on my current WP (version 3.5.1)

$current_page = max( 1, get_query_var('paged') );
$total_pages = $wp_query->max_num_pages;
echo 'Page '.$current_page.' of '.$total_pages;

Result = Page 3 of 51

Upvotes: 10

Constantin
Constantin

Reputation: 2318

use get_query_var example $page = get_query_var('paged'); in your case it's 5

Upvotes: 17

Krynble
Krynble

Reputation: 614

Found a nice solution and I'd like to share it here for I was looking for exactly the same thing!

http://wordpress.org/support/topic/get-current-page-number-for-paginated-posts

So it's like:

<?php echo '(Page '.$page.' of '.$numpages.')'; ?>

Upvotes: 2

Related Questions