DedeCMS實(shí)現(xiàn)靜態(tài)列表支持鍵盤左右翻頁[織夢網(wǎng)站模板使用教程]

閱讀 ?·? 發(fā)布日期 2019-05-27 08:29 ?·? admin

 DedeCMS實(shí)現(xiàn)靜態(tài)列表支持鍵盤左右翻頁[織夢網(wǎng)站模板使用教程] DedeCMS列表頁支持鍵盤翻上、下頁功能會讓用戶體驗(yàn)翻頁十分方便,SEO博客、圖片站采用這樣的功能將為網(wǎng)站帶來更多的PV。開發(fā)上、下翻頁功能并不復(fù)雜,結(jié)合DedeCMS,[織夢網(wǎng)站模板使用教程]SEO整合了這個(gè)功能,并修正首頁和第一頁分頁內(nèi)容重復(fù)問題,以適合SEO優(yōu)化。

支持鍵盤左右鍵翻頁JS部分

<script type="text/javascript" src="jquery.js"></script><!--引入jquery-->
<script type="text/javascript"> $(document).ready(function(){
    var prevpage=$("#pre").attr("href");
    var nextpage=$("#next").attr("href");
    $("body").keydown(function(event){
      if(event.keyCode==37 && prevpage!=undefined) location=prevpage;
      if(event.keyCode==39 && nextpage!=undefined) location=nextpage;
    });
 }); 
</script>

       控制的列表上、下頁<a>標(biāo)簽如下

<a id="pre" href="list_1_1">上一頁</a>
<a id="next" href="list_1_3">下一頁</a>

       但是DedeCMS默認(rèn)的上、下頁格式并沒有單獨(dú)調(diào)用的標(biāo)簽。下面是實(shí)現(xiàn)方法:

靜態(tài)分頁單獨(dú)調(diào)用上下頁鏈接

       打開/include/arc.listview.class.php,修改靜態(tài)分頁列表部分(動(dòng)態(tài)分頁感興趣的童鞋自己研究一下吧),找到

return $plist;
}
/**
 *  獲取動(dòng)態(tài)的分頁列表

       前面加上

$plist = '';
if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
if(preg_match('/end/i', $listitem)) $plist .= $endpage;
if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
if(preg_match('/info/i', $listitem)) $plist .= $maininfo;

       這樣修改,按照自己的實(shí)際需求,可以單獨(dú)調(diào)用首頁鏈接、上一頁鏈接、頁數(shù)、下一頁鏈接、尾頁鏈接、分頁信息等。調(diào)用方法

{dede:pagelist listitem="pre"/}
{dede:pagelist listitem="next"}
{dede:pagelist listitem="index"}
{dede:pagelist listitem="option"}
{dede:pagelist listitem="pageno"}
{dede:pagelist listitem="info"}

       調(diào)用出來的HTML樣式如下:

<p class="pages">
 <ul>
  <li><a href="list_3_1.html">上一頁</li>
  <li class="thisclass"><a href="list_3_2.html">2</a></li>
  <li><a href="list_3_3.html">3</a></li>
  <li><a href="list_3_2.html">下一頁</a></li>
  <li><a href="list_3_3.html">末頁</a></li>
  <li><span class="pageinfo">共 <strong>3</strong>頁<strong>11</strong>條</span></li>
 </ul>
</p>

       實(shí)現(xiàn)鍵盤翻頁需要綁定靜態(tài)分頁的上一頁和下一頁<a>標(biāo)簽的ID,默認(rèn)是沒有ID,打開include/arc.listview.class.php,找到

/**
 *  獲取靜態(tài)的分頁列表

       繼續(xù)往下,找到

 $prepage.="<li><a href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一頁</a></li>\r\n";

       修改為

 $prepage.="<li><a id='pre' href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一頁</a></li>\r\n";

       找到

 $nextpage.="<li><a href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一頁</a></li>\r\n";

       修改為

 $nextpage.="<li><a id='next' href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一頁</a></li>\r\n";