当前位置:首页 > CMS教程 > DeDecms > 列表

dedecms5.7文章实现阅读全文功能二次开发

发布:smiling 来源: PHP粉丝网  添加日期:2014-10-17 16:48:08 浏览: 评论:0 

阅读全文功能其实在很多的流行站点都有的,比如网易,新浪等,随着文章内容的增加,当一个页面有多个分页的时候,就会显示出这个“在本页阅读全文”的链接,点击这个链接之后出现的,将是这篇文章以没有分页出现的型式,那么在dedecms5.7如何在文章内容页添加阅读全文功能呢?

这个阅读全文有什么用呢?说白了,也就是提高用户体验,下面让我们看看,怎么简单现实这个功能.

修改文件:include/arc.archives.class.php

注意:做任何修改前都要备份好原文件.

第一步:打开include/arc.archives.class.php

文件查找://issystem==-1

往下 大概 145行 找到 $this->Fields['userip'] = $this->addTableRow['userip'];

在下面一行添加:$this->Fields['body2'] = $this->addTableRow['body'];

第二步查找:$this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='".$this->ArcID."'");

在上一行添加以下代码:

  1. //阅读全文开始 
  2. if($this->TotalPage > 1) { 
  3.         //用正则匹配把分页符去掉 
  4.  $this->Fields['body2'] = preg_replace('/#p#副标题#e#/U''',$this->Fields['body2']); 
  5.  $this->SplitFields = explode("#p2222#",$this->Fields['body2']); 
  6.  $this->Fields['tmptitle'] = (emptyempty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']); 
  7.  $this->Fields['title'] = $this->Fields['tmptitle']; 
  8.  $this->TotalPage = count($this->SplitFields); 
  9.  $this->Fields['totalpage'] = $this->TotalPage; 
  10.  $TRUEfilenameall = $this->GetTruePath().$fileFirst."_all.".$this->ShortName; 
  11.  $this->ParseDMFields(1,0); 
  12.  $this->dtp->SaveTo($TRUEfilenameall); 
  13.         
  14.  if($cfg_remote_site=='Y' && $isremote == 1) 
  15.  { 
  16.         
  17.   //分析远程文件路径 
  18.   $remotefile = str_replace(DEDEROOT, ''$TRUEfilename); 
  19.   $localfile = '..'.$remotefile
  20.   //创建远程文件夹 
  21.   $remotedir = preg_replace("#[^\/]*\.html#"''$remotefile); 
  22.   $this->ftp->rmkdir($remotedir); 
  23.   $this->ftp->upload($localfile$remotefile'ascii'); 
  24.  }  //phpfensi.com 
  25. //阅读全文结束 

第三步:查找 获得静态页面分页列表,代码如下:

  1. /** 
  2.  *  获得静态页面分页列表 
  3.  * 
  4.  * @access    public 
  5.  * @param     int   $totalPage  总页数 
  6.  * @param     int   $nowPage  当前页数 
  7.  * @param     int   $aid  文档id 
  8.  * @return    string 
  9.  */ 
  10.   function GetPagebreak($totalPage$nowPage$aid
  11.     if($totalPage==1) 
  12.     { 
  13.         return ""
  14.     } 
  15.     //$PageList = "<li><a>共".$totalPage."页: </a></li>"; 
  16.     $PageList = ""
  17.     $nPage = $nowPage-1; 
  18.     $lPage = $nowPage+1; 
  19.     if($nowPage==1) 
  20.     { 
  21.         $PageList.="<a href='javascript:void(0);'><</a>"
  22.     } 
  23.     else 
  24.     { 
  25.         if($nPage==1) 
  26.         { 
  27.             $PageList.="<a href='".$this->NameFirst.".".$this->ShortName."' target='_self'><</a>"
  28.         } 
  29.         else 
  30.         { 
  31.             $PageList.="<a href='".$this->NameFirst."_".$nPage.".".$this->ShortName."' target='_self'><</a>"
  32.         } 
  33.     } 
  34.     for($i=1;$i<=$totalPage;$i++) 
  35.     { 
  36.         if($i==1) 
  37.         { 
  38.             if($nowPage!=1) 
  39.             { 
  40.                 $PageList.="<a href='".$this->NameFirst.".".$this->ShortName."' target='_self'>1</a>"
  41.             } 
  42.             else 
  43.             { 
  44.                 $PageList.="<a class=\"here\" href='javascript:void(0);' target='_self'>1</a>"
  45.             } 
  46.         } 
  47.         else 
  48.         { 
  49.             $n = $i
  50.             if($nowPage!=$i
  51.             { 
  52.                 $PageList.="<a href='".$this->NameFirst."_".$i.".".$this->ShortName."' target='_self'>".$n."</a>"
  53.             } 
  54.             else 
  55.             { 
  56.                 $PageList.="<a class=\"here\" href='javascript:void(0);' target='_self'>{$n}</a>"
  57.             } 
  58.         } 
  59.     } 
  60.     if($lPage <= $totalPage
  61.     { 
  62.         $PageList.="<a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."' target='_self'>></a>"
  63.     } 
  64.     else 
  65.     { 
  66.         $PageList.= "<a href='javascript:void(0);'>></a>"
  67.     } 
  68.        $PageList.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>"
  69.     return $PageList

也就是在return $PageList 上一行添加了一行代码:

$PageList.= "<a href='".$this->NameFirst."_all.".$this->ShortName."'>阅读全文</a>";

修改完成后,保存文件,更新一下页面就可以看到效果了.

Tags: dedecms阅读全文 dedecms文章

分享到: