[wp-trac] [WordPress Trac] #2834: Cannot conditionalize previous_posts_link() or next_posts_link()
WordPress Trac
wp-trac at lists.automattic.com
Fri May 21 22:09:46 UTC 2010
#2834: Cannot conditionalize previous_posts_link() or next_posts_link()
---------------------------+------------------------------------------------
Reporter: paulschreiber | Owner: pishmishy
Type: enhancement | Status: reopened
Priority: normal | Milestone:
Component: Template | Version: 3.0
Severity: normal | Resolution:
Keywords: |
---------------------------+------------------------------------------------
Comment(by jimisaacs):
for instance this is an example of my most recent fix in a theme. Please
pay no attention to the actual return value HTML, that is specific to the
theme. What I am showing is what I as a developer am reduced to, if I
don't want to rewrite the functions altogether.
This would be a lot easier if there were just some returns.
/**
* Gets the formatted post navigation for next and previous posts
*
* @return string HTML
*/
function mytheme_get_post_navigation( $format = '%link', $previous_text =
'← prev', $next_text = 'next →', $in_same_cat = false,
$excluded_categories = '' ) {
// Sorry, no other way to do this without completely duplicating
WordPress function
ob_start(); previous_post_link($format, $previous_text,
$in_same_cat, $excluded_categories ); $prev = ob_get_clean();
ob_start(); next_post_link($format, $next_text, $in_same_cat,
$excluded_categories ); $next = ob_get_clean();
// only set html if there are actually links available
return apply_filters( 'mytheme_post_navigation', ( $prev || $next
) ? '<nav class="post_navigation"><span class="alignleft
previous">'.$prev.'</span> <span class="alignright
next">'.$next.'</span></nav>' : '' );
}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/2834#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list