Legacy Archive (2015): Originally written in Chinese on doubixie.com and translated into English for this edition. All archive posts · Home

Click Image to Go to Next Page in DedeCMS

Original Chinese title: dedecms 点击图片进入下一页

Problem

  1. I originally wasn’t going to write this down since Baidu has tons of posts about it, but people keep copy-pasting broken code everywhere, so I’d better record the version I fixed myself. It’s actually a very simple feature: clicking an image in DedeCMS to browse to the next page of the post.

    Steps

    1. First, locate include/arc.archives.class.php and add a ClickPicNext function:

      function ClickPicNext($ismake,$aid,&$body) 
      { 
      global $cfg_rewrite; 
      if($this->NowPage!=$this->TotalPage) 
      { 
      $PageList="";
      $lPage=$this->NowPage+1; 
      if($ismake==0) //基本语法没注意,写成了=浑然不知唉...
      { 
          //动态页 主要是这个判断
          $PageList="<a href='view.php?aid=$aid&pageno=$lPage'>"."\${0}"."</a>";                 
      } 
      else 
      {
          //静态页
          $PageList="<a href='".$this->NameFirst."_".$lPage.".".$this->ShortName."'>"."\${0}"."</a>";        
      }
      if($cfg_rewrite == 'Y') 
          { 
              $PageList = str_replace(".php?aid=","-",$PageList); 
              $PageList = preg_replace("/&pageno=(\d+)/i",'-\\1.html',$PageList); 
          } 
      $body=preg_replace("/<(img|IMG)(.*)(src|SRC)=[\"|'| ]{0,}((.*)>)/isU",$PageList,$body); 
      } 
      else 
      {
      $body=preg_replace("/<(img|IMG)(.*)(src|SRC)=[\"|'| ]{0,}((.*)>)/isU",$this->GetPreNext('imgnext'),$body); 
      }
      return $body; 
      }
    2. Find:

      $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
    3. Add the following right below it:

      if($ClickPicNext){ 
      $this->Fields[$this->SplitPageField]=$this->Fields[$this->SplitPageField]; 
      }else{ 
      $this->Fields[$this->SplitPageField]=$this->ClickPicNext($ismake,$this->Fields['id'],$this->Fields[$this->SplitPageField]);
      }
    4. Find:

      $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
    5. Add the following right below it:

      $this->PreNext['imgnext'] ="<a href='$mlink'>"."\${0}"."</a>";
    6. Find:

      $this->PreNext['next'] = "下一篇:没有了 ";
    7. Add the following right below it:

      $this->PreNext['imgnext'] ="\${0}";
    8. Find:

      else if($gtype=='next') 
      { 
      $rs =  $this->PreNext['next']; 
      }
    9. Add the following right below it:

      else if($gtype=='imgnext')                  
      {   
      $rs =  $this->PreNext['imgnext'];     
      }

That’s about it