Wordpress, how can I find out if a page is active?

Does Wordpress have a feature or something like that? I need a way to check if there are any page links (Old Entries | New Entries) that will be displayed or not.

Regards,

+3
source share
3 answers

If you look at new_posts_link , you will see $ max_page and $ paged vars.

If $ pages above is up to 1, there is a link to the previous page.
This is less than $ max_page, there is a link to the next page.

So, you can perform 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();
}
+9
source

, has_next_page() wp, get_previous_posts_link() get_next_posts_link() if.

+2

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

0
source

Source: https://habr.com/ru/post/1720452/


All Articles