WordPress.org

Plugin Directory


Ignore:
Timestamp:
11/29/10 02:14:58 (3 years ago)
Author:
scribu
Message:

Add 'query' arg. (start version 2.74-alpha)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-pagenavi/trunk/core.php

    r276099 r316324  
    44 * Template tag: Boxed Style Paging 
    55 * 
    6  * @arg string $before 
    7  * @arg string $after 
    8  * @arg string|array $options Used to overwrite options set in WP-Admin -> Settings -> PageNavi 
     6 * @param array $args: 
     7 *  'before': (string) 
     8 *  'after': (string) 
     9 *  'options': (string|array) Used to overwrite options set in WP-Admin -> Settings -> PageNavi 
     10 *  'query': (object) A WP_Query instance 
    911 */ 
    10 function wp_pagenavi( $before = '', $after = '', $options = array() ) { 
    11     global $wp_query; 
     12function wp_pagenavi( $args = array() ) { 
     13    if ( !is_array( $args ) ) { 
     14        $argv = func_get_args(); 
     15        list( $before, $after, $options ) = $argv; 
     16        $query = $GLOBALS['wp_query']; 
     17    } else { 
     18        $args = wp_parse_args( $args, array( 
     19            'before' => '', 
     20            'after' => '', 
     21            'options' => array(), 
     22            'query' => $GLOBALS['wp_query'] 
     23        ) ); 
     24 
     25        extract( $args, EXTR_SKIP ); 
     26    } 
    1227 
    1328    $options = wp_parse_args( $options, PageNavi_Core::$options->get() ); 
    1429 
    15     $posts_per_page = intval( get_query_var( 'posts_per_page' ) ); 
    16  
    17     $paged = absint( get_query_var( 'paged' ) ); 
    18     if ( !$paged ) 
    19         $paged = 1; 
    20  
    21     $total_pages = absint( $wp_query->max_num_pages ); 
    22     if ( !$total_pages ) 
    23         $total_pages = 1; 
     30    $posts_per_page = intval( $query->get( 'posts_per_page' ) ); 
     31    $paged = max( 1, absint( $query->get( 'paged' ) ) ); 
     32    $total_pages = max( 1, absint( $query->max_num_pages ) ); 
    2433 
    2534    if ( 1 == $total_pages && !$options['always_show'] ) 
    2635        return; 
    2736 
    28     $request = $wp_query->request; 
    29     $numposts = $wp_query->found_posts; 
     37    $request = $query->request; 
     38    $numposts = $query->found_posts; 
    3039 
    3140    $pages_to_show = absint( $options['num_pages'] ); 
     
    5059    } 
    5160 
    52     if ( $start_page <= 0 ) 
     61    if ( $start_page < 1 ) 
    5362        $start_page = 1; 
    5463 
Note: See TracChangeset for help on using the changeset viewer.