首页 > CMS建站 > PhpCMS > 正文

【phpcms-v9】文章内容页实现点击图片进入下一页

2020-10-10 20:30:33
字体:
来源:转载
供稿:网友

在文章内容页替换{$content}为:

  1. {php $i=strrpos($pages,"href=");} 
  2. {php $str = substr($pages,$i+5,-10);} 
  3. {php $content = str_replace("<img","<strong><font color=#ff0033>点击图片 进入下一页</font></strong><a href=".$str."<img",$content);} 
  4. {php echo str_replace("/>","/></a>",$content);} 

重新生成,好了,一切OK!

注意事项:

1.内容中有包含input的请不要使用,因为{php echo str_replace("/>","/></a>",$content);}没做判断直接替换.想想内容中有input的朋友也不多,考虑到效率问题就先不写了,等想好更好的方法在判断.

2.有朋友可能想控制替换的次数,一篇文章中存在几个图片的可能性很大.我查了一下 str_replace有个可选函数,有需要的朋友可以看一下.

大家有问题就回帖留言吧,网站没改版完呢,本来不想发地址,不过想想还是发布个演示吧,大家修改起来也放心.

最近有朋友给我留言说是这个功能出现了一些小问题,请大家把具体问题描述一下,如果可能请把相关地址贴出来。下面是我结合“化蝶自在飞”版主对没有分页丢失图片的修改,再次修改了当文章到达最后分页的再次点击进入栏目页(这里大家可以自己修改,还有一个好的方式就是进入下一篇文章/上一篇文章)

  1. {if $pages}                 
  2.      <?php 
  3.         $i=strrpos($pages,"href="); 
  4.         $str = substr($pages,$i+5,-10); 
  5.         $m=strpos($pages,$str); 
  6.       
  7.         if ($m==$i+5){ 
  8.        $content = preg_replace('/(<img (.+)>)/Ui',"<a href=/"".$CATEGORY[$catid][url]."/">/${1}</a>",$content,-1); 
  9.         } 
  10.         else
  11.        $content = preg_replace('/(<img (.+)>)/Ui',"<a href=".$str."/${1}</a>",$content,-1);       //开源代码Cuoxin.com 
  12.         } 
  13.      ?> 
  14.     {/if}  
  15.     {$content

我的网站实现:

  1. <?php 
  2. $i=strrpos($pages,"href="); 
  3. $str = substr($pages,$i+5,-13); 
  4. $m=strpos($pages,$str); 
  5. if ($m!=$i+5){ 
  6. $content = preg_replace('/(<img (.+)>)/Ui',"<a href=".$str."/${1}</a>",$content,-1);        
  7. ?>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表