#28334 closed defect (bug) (duplicate)
Paginate_links : First link and previous link are break
Reported by: | nexurium | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.1 |
Component: | General | Keywords: | reporter-feedback |
Focuses: | template | Cc: |
Description
I have found a little bug into paginate_link function.
The first link and the previous link ( when current is the second link ) are broken.
You can find my correction below :
Index: wp-includes/general-template.php =================================================================== --- wp-includes/general-template.php (3.9.1) +++ wp-includes/general-template.php (copie de travail) @@ -2456,7 +2456,7 @@ $dots = false; if ( $prev_next && $current && 1 < $current ) : - $link = str_replace('%_%', 2 == $current ? '' : $format, $base); + $link = str_replace('%_%', 1 == $current ? '' : $format, $base); $link = str_replace('%#%', $current - 1, $link); if ( $add_args ) $link = add_query_arg( $add_args, $link ); @@ -2477,7 +2477,7 @@ $dots = true; else : if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : - $link = str_replace('%_%', 1 == $n ? '' : $format, $base); + $link = str_replace('%_%', $current == $n ? '' : $format, $base); $link = str_replace('%#%', $n, $link); if ( $add_args ) $link = add_query_arg( $add_args, $link );
Change History (7)
#3
follow-ups:
↓ 4
↓ 7
@
11 years ago
Note your first change can never branch, because 1 < $current there always.
The condition 1 == $i
is correct for deciding whether to skip adding "?page=$i" to archive links. Maybe your bug is that thing about a blank last page of archives that happens sometimes, I forget why, maybe because of private posts??
#4
in reply to:
↑ 3
@
11 years ago
Replying to kitchin:
Maybe your bug is that thing about a blank last page of archives that happens sometimes, I forget why, maybe because of private posts??
Every pagination issue I've seen so far was caused by using query_posts(). If you need to modify the main query, pre_get_posts should be used instead.
#6
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Duplicate of #24606.
#7
in reply to:
↑ 3
@
11 years ago
Replying to kitchin:
Note your first change can never branch, because 1 < $current there always.
The condition
1 == $i
is correct for deciding whether to skip adding "?page=$i" to archive links. Maybe your bug is that thing about a blank last page of archives that happens sometimes, I forget why, maybe because of private posts??
I'm ok,
My first change is not good, but the condition 2 == $current
is not good too. if current is the second page the previous link must be 1 dans not ""
I use the paginate_link into a widget :
// The Query $query = new WP_Query($args); // The Loop if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); .... } }else{ get_template_part( 'content', 'none' ); } ?> <div id="pagination-<?php echo $widget_id?>" class="pagination-mae-list"> <?php if ($current_country != '') $format = '?current_country_mae_list-'.$widget_id.'='.$current_country.'&'; else $format = '?'; echo paginate_links(array( 'format' => $format.'current_page_mae_list-'.$widget_id.'=%#%', 'current' => max(1, $current), 'total' => $query->max_num_pages, 'end_size' => 3, 'mid_size' => 3, 'prev_text' => '<< ', 'next_text' => '>> ' )); ?> </div>
Introduced in [4275], modified in [4276].
Could you describe what exactly is broken and provide the steps to reproduce the issue?