Skip to content

Commit

Permalink
fixes search and tag pagination issue (problem with the action of the…
Browse files Browse the repository at this point in the history
… search form)
  • Loading branch information
jaredharbour committed Dec 4, 2012
1 parent ae20efc commit 72588c0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 226 deletions.
225 changes: 0 additions & 225 deletions hopper/grinder/espresso-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,230 +333,6 @@ function espresso_pagenavi($pages = '', $range = 2)
}
}


function wp_pagenavi( $args = array() ) {
echo 'wp_pagenavi';
if ( !is_array( $args ) ) {
$argv = func_get_args();
$args = array();
foreach ( array( 'before', 'after', 'options' ) as $i => $key )
$args[ $key ] = $argv[ $i ];
}

$args = wp_parse_args( $args, array(
'before' => '',
'after' => '',
'options' => array(),
'query' => $GLOBALS['wp_query'],
'type' => 'posts',
'echo' => true
) );

extract( $args, EXTR_SKIP );

//$options = wp_parse_args( $options, PageNavi_Core::$options->get() );

$instance = new PageNavi_Call( $args );

list( $posts_per_page, $paged, $total_pages ) = $instance->get_pagination_args();

$pages_to_show = 5;
$larger_page_to_show = 3;
$larger_page_multiple = 10;
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor( $pages_to_show_minus_1/2 );
$half_page_end = ceil( $pages_to_show_minus_1/2 );
$start_page = $paged - $half_page_start;

if ( $start_page <= 0 )
$start_page = 1;

$end_page = $paged + $half_page_end;

if ( ( $end_page - $start_page ) != $pages_to_show_minus_1 )
$end_page = $start_page + $pages_to_show_minus_1;

if ( $end_page > $total_pages ) {
$start_page = $total_pages - $pages_to_show_minus_1;
$end_page = $total_pages;
}

if ( $start_page < 1 )
$start_page = 1;

$out = '';

// Text
// if ( !empty( $options['pages_text'] ) ) {
// $pages_text = str_replace(
// array( "%CURRENT_PAGE%", "%TOTAL_PAGES%" ),
// array( number_format_i18n( $paged ), number_format_i18n( $total_pages ) ),
// $options['pages_text'] );
// $out .= "<span class='pages'>$pages_text</span>";
// }

if ( $start_page >= 2 && $pages_to_show < $total_pages ) {
// First
$first_text = str_replace( '%TOTAL_PAGES%', number_format_i18n( $total_pages ), $options['first_text'] );
$out .= $instance->get_single( 1, 'first', $first_text, '%TOTAL_PAGES%' );
}

// Previous
if ( $paged > 1 && !empty( $options['prev_text'] ) )
$out .= $instance->get_single( $paged - 1, 'previouspostslink', $options['prev_text'] );

if ( $start_page >= 2 && $pages_to_show < $total_pages ) {
if ( !empty( $options['dotleft_text'] ) )
$out .= "<span class='extend'>{$options['dotleft_text']}</span>";
}

// Smaller pages
$larger_pages_array = array();
if ( $larger_page_multiple )
for ( $i = $larger_page_multiple; $i <= $total_pages; $i+= $larger_page_multiple )
$larger_pages_array[] = $i;

$larger_page_start = 0;
foreach ( $larger_pages_array as $larger_page ) {
if ( $larger_page < ($start_page - $half_page_start) && $larger_page_start < $larger_page_to_show ) {
$out .= $instance->get_single( $larger_page, 'smaller page', $options['page_text'] );
$larger_page_start++;
}
}

if ( $larger_page_start )
$out .= "<span class='extend'>{$options['dotleft_text']}</span>";

// Page numbers
$timeline = 'smaller';
foreach ( range( $start_page, $end_page ) as $i ) {
if ( $i == $paged && !empty( $options['current_text'] ) ) {
$current_page_text = str_replace( '%PAGE_NUMBER%', number_format_i18n( $i ), $options['current_text'] );
$out .= "<span class='current'>$current_page_text</span>";
$timeline = 'larger';
} else {
$out .= $instance->get_single( $i, "page $timeline", $options['page_text'] );
}
}

// Large pages
$larger_page_end = 0;
$larger_page_out = '';
foreach ( $larger_pages_array as $larger_page ) {
if ( $larger_page > ($end_page + $half_page_end) && $larger_page_end < $larger_page_to_show ) {
$larger_page_out .= $instance->get_single( $larger_page, 'larger page', $options['page_text'] );
$larger_page_end++;
}
}

if ( $larger_page_out ) {
$out .= "<span class='extend'>{$options['dotright_text']}</span>";
}
$out .= $larger_page_out;

if ( $end_page < $total_pages ) {
if ( !empty( $options['dotright_text'] ) )
$out .= "<span class='extend'>{$options['dotright_text']}</span>";
}

// Next
if ( $paged < $total_pages && !empty( $options['next_text'] ) )
$out .= $instance->get_single( $paged + 1, 'nextpostslink', $options['next_text'] );

if ( $end_page < $total_pages ) {
// Last
$out .= $instance->get_single( $total_pages, 'last', $options['last_text'], '%TOTAL_PAGES%' );
}




$out = $before . "<div class='wp-pagenavi'>\n$out\n</div>" . $after;

$out = apply_filters( 'wp_pagenavi', $out );

if ( !$echo )
return $out;

echo $out;
}


class PageNavi_Call {

protected $args;

function __construct( $args ) {
$this->args = $args;
}

function __get( $key ) {
return $this->args[ $key ];
}

function get_pagination_args() {
global $numpages;

$query = $this->query;

switch( $this->type ) {
case 'multipart':
// Multipart page
$posts_per_page = 1;
$paged = max( 1, absint( get_query_var( 'page' ) ) );
$total_pages = max( 1, $numpages );
break;
case 'users':
// WP_User_Query
$posts_per_page = $query->query_vars['number'];
$paged = max( 1, floor( $query->query_vars['offset'] / $posts_per_page ) + 1 );
$total_pages = max( 1, ceil( $query->total_users / $posts_per_page ) );
break;
default:
// WP_Query
$posts_per_page = intval( $query->get( 'posts_per_page' ) );
$paged = max( 1, absint( $query->get( 'paged' ) ) );
$total_pages = max( 1, absint( $query->max_num_pages ) );
break;
}

return array( $posts_per_page, $paged, $total_pages );
}

function get_single( $page, $class, $raw_text, $format = '%PAGE_NUMBER%' ) {
if ( empty( $raw_text ) )
return '';

$text = str_replace( $format, number_format_i18n( $page ), $raw_text );

return "<a href='" . esc_url( $this->get_url( $page ) ) . "' class='$class'>$text</a>";
}

function get_url( $page ) {
return ( 'multipart' == $this->type ) ? get_multipage_link( $page ) : get_pagenum_link( $page );
}
}

# http://core.trac.wordpress.org/ticket/16973
if ( !function_exists( 'get_multipage_link' ) ) :
function get_multipage_link( $page = 1 ) {
global $post, $wp_rewrite;

if ( 1 == $page ) {
$url = get_permalink();
} else {
if ( '' == get_option('permalink_structure') || in_array( $post->post_status, array( 'draft', 'pending') ) )
$url = add_query_arg( 'page', $page, get_permalink() );
elseif ( 'page' == get_option( 'show_on_front' ) && get_option('page_on_front') == $post->ID )
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $wp_rewrite->pagination_base . "/$page", 'single_paged' );
else
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $page, 'single_paged' );
}

return $url;
}
endif;

/**
* Espresso Import Options
*
Expand Down Expand Up @@ -608,6 +384,5 @@ function espresso_import_options($import_data){






2 changes: 1 addition & 1 deletion searchform.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
<form action="<?php echo esc_url( home_url( '/' ) ); ?>" id="searchform" method="get">
<div>
<label for="s" class="screen-reader-text">Search for:</label>
<input type="text" id="s" name="s" value="" />
Expand Down

0 comments on commit 72588c0

Please sign in to comment.