• Hello guys,

    I have a problem with our pagination in combination with the search.

    We use pagination code from:


    function fb_paging_bar( $args = array() ) {
    define("FB_GREYFOTO_TEXTDOMAIN", "");

    $defaults = array(
    'range' => 6,
    'custom_query' => FALSE,
    'previous_string' => __( '«', FB_GREYFOTO_TEXTDOMAIN ),
    'next_string' => __( '»', FB_GREYFOTO_TEXTDOMAIN ),
    'view_fp' => FALSE,
    'view_lp' => FALSE,
    'before_output' => '<div class="postlink">',
    'after_output' => '</div>'
    );

    $args = wp_parse_args(
    $args,
    apply_filters( 'fb_paging_bar_defaults', $defaults )
    );

    $args['range'] = (int) $args['range'] - 1;
    if ( !$args['custom_query'] )
    $args['custom_query'] = @$GLOBALS['wp_query'];
    $count = (int) $args['custom_query']->max_num_pages;
    $page = intval( get_query_var( 'paged' ) );
    $ceil = ceil( $args['range'] / 2 );

    if ( $count <= 1 )
    return FALSE;

    if ( !$page )
    $page = 1;

    if ( $count > $args['range'] ) {
    if ( $page <= $args['range'] ) {
    $min = 1;
    $max = $args['range'] + 1;
    } elseif ( $page >= ($count - $ceil) ) {
    $min = $count - $args['range'];
    $max = $count;
    } elseif ( $page >= $args['range'] && $page < ($count - $ceil) ) {
    $min = $page - $ceil;
    $max = $page + $ceil;
    }
    } else {
    $min = 1;
    $max = $count;
    }

    $echo = '';
    $previous = intval($page) - 1;
    $previous = esc_attr( get_pagenum_link($previous) );
    if ( $previous && (1 != $page) )
    $echo .= '' . $args['previous_string'] . '';
    $firstpage = esc_attr( get_pagenum_link(1) );

    if ( $args['view_fp'] && $firstpage && (1 != $page) )
    $echo .= '' . __( 'first', FB_GREYFOTO_TEXTDOMAIN ) . '';

    if ( !empty($min) && !empty($max) ) {
    for( $i = $min; $i <= $max; $i++ ) {
    if ($page == $i) {
    $echo .= '<span class="current">' . str_pad( (int)$i, 2, '0', STR_PAD_LEFT ) . '</span>';
    } else {
    $echo .= sprintf( '%002d', esc_attr( get_pagenum_link($i) ), $i );
    }
    }
    }

    if ($args['view_lp']) {
    $lastpage = esc_attr( get_pagenum_link($count) );
    if ( $lastpage && ($count != $page) ) {
    $count = str_pad( (int)$count, 2, '0', STR_PAD_LEFT );
    $echo .= '' . __( 'last', FB_GREYFOTO_TEXTDOMAIN ) . ' (' . $count . ')' . '';
    }
    }

    $next = intval($page) + 1;
    $next = esc_attr( get_pagenum_link($next) );
    if ($next && ($count != $page) )
    $echo .= '' . $args['next_string'] . '';

    if ( isset($echo) )
    echo $args['before_output'] . $echo . $args['after_output'];
    }

    Code from our search template:


    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

    query_posts(paged$page");
    if (have_posts()) : while (have_posts()) : the_post();
    ....

    Result:
    First page work fine.. but if I click on pagination for second page.. I lose all informations..

    Does anyone have any suggestion to solve this problem?

  • The topic ‘Search page pagination does not work’ is closed to new replies.