Finding current page number in Wordpress

2020-07-01 08:14发布

I have added the following custom loop in my Wordpress template:

$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 paged with the current page number. What is the way to get the current page number in Wordpress?

标签: php wordpress
5条回答
老娘就宠你
2楼-- · 2020-07-01 08:23

Not near a wordpress system to test this out at the mo, but you should be able to use:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

(obviously defaulting to 1, if it has not been sent through).

查看更多
可以哭但决不认输i
3楼-- · 2020-07-01 08:23

using variable $paged.

global $paged;
echo $paged;
查看更多
ら.Afraid
4楼-- · 2020-07-01 08:24

For 'Page x of y' I use this:

<?php 

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
echo $paged.' of '.$wp_query->max_num_pages; 

?>
查看更多
闹够了就滚
5楼-- · 2020-07-01 08:31

This worked for me:

<?php echo '(Page '.$page.' of '.$wp_query->max_num_pages.')'; ?>
查看更多
该账号已被封号
6楼-- · 2020-07-01 08:45

Use get_query_var('paged') like this

<?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); 
?>
查看更多
登录 后发表回答