[wp-trac] [WordPress Trac] #37260: Request: Functions to check if there's a 2nd page

WordPress Trac noreply at wordpress.org
Sun Jul 24 14:53:40 UTC 2016


#37260: Request: Functions to check if there's a 2nd page
--------------------------+------------------------------
 Reporter:  henry.wright  |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  4.5.3
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  template
--------------------------+------------------------------

Comment (by Jonnyauk):

 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:
 {{{#!php
 <?php
 $prev_link = get_previous_post_link('« %link');
 $next_link = get_next_post_link('« %link');
 ?>
 }}}

 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:

 {{{#!php
 <?php
 echo get_previous_post_link('<p class="link-previous-post">«
 %link</p>');
 echo get_next_post_link('<p class="link-next-post">« %link</p>');
 ?>
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37260#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list