php 在 Wordpress 中查找当前页码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1031442/
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
Finding current page number in Wordpress
提问by Simon Scarfe
I have added the following custom loop in my Wordpress template:
我在我的 Wordpress 模板中添加了以下自定义循环:
$args = array(
'category__not_in' => array($featured_cat->term_id),
'posts_per_page' => 10,
'post__not_in' => array($recent_post)
);
query_posts($args);
For pagination to work, I guess I need to pass another arg pagedwith the current page number. What is the way to get the current page number in Wordpress?
为了分页工作,我想我需要传递另一个paged带有当前页码的参数。在Wordpress中获取当前页码的方法是什么?
回答by Simon Scarfe
Not near a wordpress system to test this out at the mo, but you should be able to use:
不是在 wordpress 系统附近进行测试,但您应该能够使用:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
(obviously defaulting to 1, if it has not been sent through).
(显然默认为 1,如果还没有发送通过)。
回答by Pham
using variable $paged.
使用变量 $paged。
global $paged;
echo $paged;
回答by nick
For 'Page x of y' I use this:
对于 'Page x of y' 我使用这个:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo $paged.' of '.$wp_query->max_num_pages;
?>
回答by user27068
This worked for me:
这对我有用:
<?php echo '(Page '.$page.' of '.$wp_query->max_num_pages.')'; ?>
回答by aaronwaggs
Use get_query_var('paged')like this
get_query_var('paged')像这样使用
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('category__not_in' => array($featured_cat->term_id), 'posts_per_page' => 10, 'post__not_in' => array($recent_post), 'paged' => $paged );
query_posts($args);
?>

