wordpress wordpress分页从url获取当前页码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8281395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wordpress pagination get current page number from url
提问by Samik Chattopadhyay
I need to extract the value of "page" i.e 5 from this url - http://snypher.local/photos/page/5What should I do to extract it in Wordpress? I am not able to get it from the $_GET super global.
我需要从这个 url 中提取“页面”的值,即 5 - http://snypher.local/photos/page/5我应该怎么做才能在 Wordpress 中提取它?我无法从 $_GET 超级全局获取它。
回答by Constantin
use get_query_var
example $page = get_query_var('paged');
in your case it's 5
在你的情况下使用get_query_var
例子$page = get_query_var('paged');
它是5
回答by Samik Chattopadhyay
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.
我已经使用这个函数从 url 中获取变量 page 的值。
回答by Rameez SOOMRO
its work fine i've tested on my current WP (version 3.5.1)
它的工作正常我已经在我当前的 WP(版本 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
结果 = 第 3 页,共 51 页
回答by Krynble
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
http://wordpress.org/support/topic/get-current-page-number-for-paginated-posts
So it's like:
所以它就像:
<?php echo '(Page '.$page.' of '.$numpages.')'; ?>