WordPress 默认给主题开发者的建议是在文章列表底部提供上下页按钮,所以没有提供直接用在文章列表下的分页导航的函数。这里我提供一个比较完善的分页导航函数。
/** *WordPress 文章列表分页导航 *http://www.endskin.com/page-navi/ */ function Bing_get_pagenavi( $query = false, $num = false, $before = '<article class="pagenavi postlistpagenavi">', $after = '</article>', $options = array() ){ global $wp_query; $options = wp_parse_args( $options, array( 'pages_text' => '%CURRENT_PAGE%/%TOTAL_PAGES%', 'current_text' => '%PAGE_NUMBER%', 'page_text' => '%PAGE_NUMBER%', 'first_text' => __( '« 首页', 'Bing' ), 'last_text' => __( '尾页 »', 'Bing' ), 'next_text' => __( '»', 'Bing' ), 'prev_text' => '«', 'dotright_text' => '...', 'dotleft_text' => '...', 'num_pages' => 5, 'always_show' => 0, 'num_larger_page_numbers' => 3, 'larger_page_numbers_multiple' => 10 ) ); if( $wp_query->max_num_pages <= 1 || is_single() ) return; if( !empty( $query ) ){ $request = $query->request; $numposts = $query->found_posts; $max_page = $query->max_num_pages; $posts_per_page = intval( $num ); }else{ $request = $wp_query->request; $numposts = $wp_query->found_posts; $max_page = $wp_query->max_num_pages; $posts_per_page = intval( get_query_var( 'posts_per_page' ) ); } $paged = intval( get_query_var( 'paged' ) ); if( empty( $paged ) || $paged == 0 ) $paged = 1; $pages_to_show = intval( $options['num_pages'] ); $larger_page_to_show = intval( $options['num_larger_page_numbers'] ); $larger_page_multiple = intval( $options['larger_page_numbers_multiple'] ); $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 > $max_page ){ $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if( $start_page <= 0 ) $start_page = 1; $larger_per_page = $larger_page_to_show * $larger_page_multiple; $larger_start_page_start = ( ( floor( $start_page / 10 ) * 10 ) + $larger_page_multiple ) - $larger_per_page; $larger_start_page_end = floor( $start_page / 10 ) * 10 + $larger_page_multiple; $larger_end_page_start = floor( $end_page / 10 ) * 10 + $larger_page_multiple; $larger_end_page_end = floor( $end_page / 10 ) * 10 + ( $larger_per_page ); if( $larger_start_page_end - $larger_page_multiple == $start_page ){ $larger_start_page_start = $larger_start_page_start - $larger_page_multiple; $larger_start_page_end = $larger_start_page_end - $larger_page_multiple; } if( $larger_start_page_start <= 0 ) $larger_start_page_start = $larger_page_multiple; if( $larger_start_page_end > $max_page ) $larger_start_page_end = $max_page; if( $larger_end_page_end > $max_page ) $larger_end_page_end = $max_page; if( $max_page > 1 || intval( $options['always_show'] ) == 1 ){ $pages_text = str_replace( '%CURRENT_PAGE%', number_format_i18n( $paged ), $options['pages_text'] ); $pages_text = str_replace( '%TOTAL_PAGES%', number_format_i18n( $max_page ), $pages_text); echo $before; if( !empty( $pages_text ) ) echo '<span class="pages">' . $pages_text . '</span>'; if( $start_page >= 2 && $pages_to_show < $max_page ){ $first_page_text = str_replace( '%TOTAL_PAGES%', number_format_i18n( $max_page ), $options['first_text'] ); echo '<a href="' . esc_url( get_pagenum_link() ) . '" class="first" title="' . $first_page_text . '">' . $first_page_text . '</a>'; } if( $larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page ){ for( $i = $larger_start_page_start;$i < $larger_start_page_end;$i += $larger_page_multiple ){ $page_text = str_replace( '%PAGE_NUMBER%', number_format_i18n( $i ), $options['page_text'] ); echo '<a href="' . esc_url( get_pagenum_link( $i ) ) . '" class="page" title="' . $page_text . '">' . $page_text . '</a>'; } } previous_posts_link( $options['prev_text'] ); for( $i = $start_page;$i <= $end_page;$i++ ){ if( $i == $paged ){ $current_page_text = str_replace( '%PAGE_NUMBER%', number_format_i18n( $i ), $options['current_text'] ); echo '<span class="current">' . $current_page_text . '</span>'; }else{ $page_text = str_replace( '%PAGE_NUMBER%', number_format_i18n( $i ), $options['page_text'] ); echo '<a href="' . esc_url( get_pagenum_link( $i ) ).'" class="page" title="' . $page_text . '">' . $page_text . '</a>'; } } if( empty( $query ) ) echo '<span id="next-page">'; next_posts_link( $options['next_text'], $max_page ); if( empty( $query ) ) echo '</span>'; } if( $larger_page_to_show > 0 && $larger_end_page_start < $max_page ){ for( $i = $larger_end_page_start;$i <= $larger_end_page_end;$i += $larger_page_multiple ){ $page_text = str_replace( '%PAGE_NUMBER%', number_format_i18n( $i ), $options['page_text'] ); echo '<a href="' . esc_url( get_pagenum_link( $i ) ).'" class="page" title="' . $page_text . '">' . $page_text . '</a>'; } } if( $end_page < $max_page ){ $last_page_text = str_replace( '%TOTAL_PAGES%', number_format_i18n( $max_page ), $options['last_text'] ); echo '<a href="' . esc_url( get_pagenum_link( $max_page ) ) . '" class="last" title="' . $last_page_text . '">' . $last_page_text . '</a>'; } echo $after; }
然后在需要使用分页导航的地方添加下边的代码:
<?php if( function_exists( 'Bing_get_pagenavi' ) ) Bing_get_pagenavi(); ?>
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 陈曦《遇见HQCD》[WAV+CUE]
- 大提琴-刘欣欣《爱的问候》HDCD[WAV+CUE]
- 周耀辉/邓慧中《从什么时候开始》[320K/MP3][95.71MB]
- 周耀辉/邓慧中《从什么时候开始》[FLAC/分轨][361.29MB]
- 蒋荣宗《蒋荣宗ZONG x FOCA 夏日马戏节》[320K/MP3][89.28MB]
- 坣娜.1997-你怎么可以不爱我【巨石】【WAV+CUE】
- 群星.1992-暗恋桃花源电影原声带【滚石】【WAV+CUE】
- 林隆璇.1989-愤怒的情歌【巨石】【WAV+CUE】
- 勤琴《海上花》[DTS-WAV分轨]
- 群星《歌声有故事》[DTS-WAV分轨]
- [发烧人声]群星《邂逅》DTS-WAV
- 艻打绿《夏/狂热(苏打绿版)》[320K/MP3][106.42MB]
- 艻打绿《夏/狂热(苏打绿版)》[FLAC分轨][574.2MB]
- 黄雨勳《魔法列车首部曲》[320K/MP3][33.1MB]
- 李蕙敏.2014-记得·销魂新歌+精丫乐意唱片】【WAV+CUE】