当前位置 : 主页 > 网站建设 > 正文

DedeCMS实现静态列表支持键盘左右翻页

原创

重庆seo2017-01-11 16:40:30阅读()用户体验dedecmsJS页面分页A+ / A-

DedeCMS实现静态列表支持键盘左右翻页

       DedeCMS列表页支持键盘翻上、下页功能会让用户体验翻页十分方便,SEO博客、图片站采用这样的功能将为网站带来更多的PV。开发上、下翻页功能并不复杂,结合DedeCMS,吖七SEO整合了这个功能,并修正首页和第一页分页内容重复问题,以适合SEO优化。

支持键盘左右键翻页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>标签如下

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

       但是DedeCMS默认的上、下页格式并没有单独调用的标签。下面是实现方法:

静态分页单独调用上下页链接

       打开/include/arc.listview.class.php,修改静态分页列表部分(动态分页感兴趣的童鞋自己研究一下吧),找到

return $plist;
}
/**
 *  获取动态的分页列表

       前面加上

$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;

       这样修改,按照自己的实际需求,可以单独调用首页链接、上一页链接、页数、下一页链接、尾页链接、分页信息等。调用方法

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

       调用出来的HTML样式如下:

<div 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>
</div>

       实现键盘翻页需要绑定静态分页的上一页和下一页<a>标签的ID,默认是没有ID,打开include/arc.listview.class.php,找到

/**
 *  获取静态的分页列表

       继续往下,找到

 $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";

       注意到静态列表和分页第一页内容是重复的,URL不同,不利于SEO优化,参考文章《SEO列表分页标题优化第一页与首页链接重复》进行相应修改,修改后注意给上一页和下一页增加ID。

    扩展阅读

    本文地址:https://www.vi586.com/web/358.html
    版权声明:原创文章,版权归重庆SEO吖七所有,欢迎分享本文,支持原创,转载请保留出处

    赞(2)