#37260 closed feature request (invalid)
Request: Functions to check if there's a 2nd page
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.5.3 |
Component: | General | Keywords: | close |
Focuses: | template | Cc: |
Description
Sometimes it's useful to wrap a pagination function in HTML:
<nav><?php some_wp_pag_function(); ?></nav>
But if there's no 2nd page, we're left with markup such as:
<nav> </nav>
It would be useful to have a set of functions available which check if there's a 2nd page so we could do stuff like this:
if ( is_there_a_second_page() ) { ?> <nav><?php some_wp_pag_function(); ?></nav> <?php }
Things that can be paginated which spring to mind are:
- Posts
- Comments
- A single post via
<!-- nextpage -->
Change History (6)
#4
@
9 years ago
- Resolution set to invalid
- Status changed from new to closed
You were right in trying to avoid empty markup - no-one wants that sir ;)
I hope this works out for you - it would certainly negate your request for a new function. There is so many cool, handy functions like this hiding away in WordPress ready to use ;)
Note: See
TracTickets for help on using
tickets.
I think you should probably check out the functions get_previous_post_link() and get_next_post_link() - that's what I've used to avoid the empty markup as you outline in your example. Visit the links below for full documentation.
https://developer.wordpress.org/reference/functions/get_next_post_link/
https://developer.wordpress.org/reference/functions/get_previous_post_link/
This would allow you to do something like this:
Once you have those set as variables, you can then conditionally test against, and display those variables, so a new function as you suggest is not really required ;) Also worth noting is that the first parameter is the 'format' of the output link, so you can do things like below - and it will only output if a link exists: