咖喱饭饭 發表於 2023-11-19 00:00:00

wordpress上一页下一页无插件分页函数实例

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
本文实例讲述了wordpress上一页下一页无插件分页函数。分享给大家供大家参考。具体分析如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这里提供两个,一个是willin提供的,一个则是今天我提供的,其实就都是简单的修改,但可应对不同需求的应用.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
第一个可以定制显示wordpress显示上一页下一页,及统计页数及中间页数,代码如下:<br>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
if ( !function_exists('pagenavi') ) { <br>
function pagenavi( $p = 5 ) { // 取当前页前后各 2 页 <br>
if ( is_singular() ) return; // 文章与插页不用 <br>
global $wp_query, $paged; <br>
$max_page = $wp_query-&gt;max_num_pages; <br>
if ( $max_page == 1 ) return; // 只有一页不用 <br>
if ( emptyempty( $paged ) ) $paged = 1; <br>
echo '&lt;span&gt;Page: ' . $paged . ' of ' . $max_page . ' &lt;/span&gt; '; // 显示页数 <br>
if ( $paged &gt; 1 ) p_link( $paged - 1, '上一页', '« Previous' );/* 如果当前页大于1就显示上一页链接 */ <br>
if ( $paged &gt; $p + 1 ) p_link( 1, '最前页' ); <br>
if ( $paged &gt; $p + 2 ) echo '... '; <br>
for( $i = $paged - $p; $i &lt;= $paged + $p; $i++ ) { // 中间页 <br>
if ( $i &gt; 0 &amp;&amp; $i &lt;= $max_page ) $i == $paged ? print "&lt;span class='page-numbers current'&gt;{$i}&lt;/span&gt; " : p_link( $i ); <br>
} <br>
if ( $paged &lt; $max_page - $p - 1 ) echo '... '; <br>
if ( $paged &lt; $max_page - $p ) p_link( $max_page, '最后页' ); <br>
if ( $paged &lt; $max_page ) p_link( $paged + 1,'下一页', 'Next »' );/* 如果当前页不是最后一页显示下一页链接 */ <br>
} <br>
function p_link( $i, $title = '', $linktype = '' ) { <br>
if ( $title == '' ) $title = "第 {$i} 页"; <br>
if ( $linktype == '' ) { $linktext = $i; } else { $linktext = $linktype; } <br>
echo "&lt;a class='page-numbers' href='", esc_html( get_pagenum_link( $i ) ), "' /&gt;
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>第二个就是今天主要分享的,只显示上一页下一页,可定制样式,实例代码如下:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
if ( !function_exists('pagenavi') ) { <br>
function pagenavi( ) { <br>
if ( is_singular() ) return; // 文章与插页不用 <br>
global $wp_query, $paged; <br>
$max_page = $wp_query-&gt;max_num_pages; <br>
if ( emptyempty( $paged ) ) $paged = 1; <br>
if ( $paged &gt; 1 ) p_linkp( $paged - 1, '上一页' );/* 如果当前页大于1就显示上一页链接 */ <br>
if ( $paged == 1 ) p_linkp1( $paged );/* 如果当前页等于1就显示灰色链接 */ <br>
if ( $paged &lt; $max_page ) p_linkn( $paged + 1,'下一页' );/* 如果当前页不是最后一页显示下一页链接 */ <br>
if ( $paged == $max_page ) p_linkp0( $paged );/* 如果当前页等于最后一页显示灰色链接 */ <br>
} <br>
function p_linkp( $i, $title = '', $linktype = '' ) { <br>
echo "&lt;div class='pre-page page'&gt;&lt;a href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}'&gt;{$linktext}&lt;/a&gt;&lt;/div&gt; "; <br>
} <br>
function p_linkn( $i, $title = '', $linktype = '' ) { <br>
echo "&lt;div class='next-page page'&gt;&lt;a href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}'&gt;{$linktext}&lt;/a&gt;&lt;/div&gt; "; <br>
} <br>
function p_linkp0() { <br>
echo "&lt;div class='pre-page page nav0'&gt;&lt;/a&gt;&lt;/div&gt; "; <br>
} <br>
function p_linkp1() { <br>
echo "&lt;div class='pre-page page nav1'&gt;&lt;/a&gt;&lt;/div&gt; "; <br>
} <br>
}</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
希望本文所述对大家的WordPress建站有所帮助。</p>

</div>
    <div>
<script>dy("nrwz");</script>
</div>
<div>

</div>
頁: [1]
查看完整版本: wordpress上一页下一页无插件分页函数实例