Uffo
Uffo

Reputation: 10056

Wordpress how can I know if the pagination is active?

Has Wordpress a function or something like that?I need a way to check if there are any page links(Older Entries | Newer Entries)to be displayed or not.

Best Regards,

Upvotes: 3

Views: 5878

Answers (3)

cnotethegr8
cnotethegr8

Reputation: 7510

As Marcus said, the function has_next_page() doesn't work for newer wp versions, so you can simply use get_previous_posts_link() and get_next_posts_link() inside an if statement.

Upvotes: 2

crosenblum
crosenblum

Reputation: 1927

Although like many i use the pagenavi plugin by Lester Chan.right http://lesterchan.net/wordpress/readme/wp-pagenavi.html

Upvotes: -1

Damien MATHIEU
Damien MATHIEU

Reputation: 32627

If you look at the new_posts_link function, you'll see a $max_page and $paged vars.

If the $pages is higher to 1, there is a previous page link.
It it's smaller to $max_page, there is a next page link.

So you can do the following functions :

# Will return true if there is a next page
function has_next_page() {
    global $paged, $max_page;
    return $paged < $max_page;
}

# Will return true if there is a previous page
function has_previous_page() {
    global $paged;
    return $paged > 1;
}

# Will return true if there is more than one page (either before or after).
function has_pagination() {
    return has_next_page() or has_previous_page();
}

Upvotes: 11

Related Questions