Make WordPress Core


Ignore:
Timestamp:
04/22/2009 08:44:37 AM (16 years ago)
Author:
azaozz
Message:

Add a complementary get_* function for posts_nav_link(), props filosofo, fixes #9094

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r11013 r11049  
    14231423
    14241424/**
     1425 * Return post pages link navigation for previous and next pages.
     1426 *
     1427 * @since 2.8
     1428 *
     1429 * @param string|array $args Optional args.
     1430 * @return string The posts link navigation.
     1431 */
     1432function get_posts_nav_link( $args = array() ) {
     1433    global $wp_query;
     1434   
     1435    $return = '';
     1436
     1437    if ( !is_singular() ) {
     1438        $defaults = array(
     1439            'sep' => ' — ',
     1440            'prelabel' => __('« Previous Page'),
     1441            'nxtlabel' => __('Next Page »'),
     1442        );
     1443        $args = wp_parse_args( $args, $defaults );
     1444
     1445        $max_num_pages = $wp_query->max_num_pages;
     1446        $paged = get_query_var('paged');
     1447
     1448        //only have sep if there's both prev and next results
     1449        if ($paged < 2 || $paged >= $max_num_pages) {
     1450            $args['sep'] = '';
     1451        }
     1452
     1453        if ( $max_num_pages > 1 ) {
     1454            $return = get_previous_posts_link($args['prelabel']);
     1455            $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $args['sep']);
     1456            $return .= get_next_posts_link($args['nxtlabel']);
     1457        }
     1458    }
     1459    return $return;
     1460
     1461}
     1462
     1463/**
    14251464 * Display post pages link navigation for previous and next pages.
    14261465 *
     
    14311470 * @param string $nxtlabel Optional Label for next pages.
    14321471 */
    1433 function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) {
    1434     global $wp_query;
    1435     if ( !is_singular() ) {
    1436         $max_num_pages = $wp_query->max_num_pages;
    1437         $paged = get_query_var('paged');
    1438 
    1439         //only have sep if there's both prev and next results
    1440         if ($paged < 2 || $paged >= $max_num_pages) {
    1441             $sep = '';
    1442         }
    1443 
    1444         if ( $max_num_pages > 1 ) {
    1445             previous_posts_link($prelabel);
    1446             echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
    1447             next_posts_link($nxtlabel);
    1448         }
    1449     }
     1472function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
     1473    $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
     1474    echo get_posts_nav_link($args);
    14501475}
    14511476
Note: See TracChangeset for help on using the changeset viewer.