wordpress pagination get current page number from url

后端 未结 4 1805
醉酒成梦
醉酒成梦 2021-01-02 07:43

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 th

相关标签:
4条回答
  • 2021-01-02 07:49
    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.

    0 讨论(0)
  • 2021-01-02 07:55

    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.')'; ?>
    
    0 讨论(0)
  • 2021-01-02 08:10

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

    0 讨论(0)
  • 2021-01-02 08:13

    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

    0 讨论(0)
提交回复
热议问题