phpcms v9取组图的第一张或第N张图为缩略图

来自:互联网
时间:2018-08-26
阅读:

phpcms v9的内容编辑器上传的图片可以获取第一张或第N张为图为缩略图,那么如果内容没有图片,而组图及多图片有图,怎样把多图片的第一张或第N张图片做为缩略图呢?

跟着下面的步骤做,就可以实现了!

1.打开相应要使用组图的模型的组图字段,添加组图 字段提示为

<div class="content_attr"> 
<label><input type='checkbox' name='auto_thumbp' value="1" checked>是否获取内容第</label><input type="text" name="auto_thumb_nop" value="1" size="2" class="">张图片作为标题图片 
</div>

2.打开phpcmsmodelcontent_model.class.php 找到如下内容

//自动提取缩略图 
  if(isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) { 
   $content = $content ? $content : stripslashes($modelinfo['content']); 
   $auto_thumb_no = intval($_POST['auto_thumb_no'])-1; 
   if(preg_match_all("/(src)=(["|']?)([^ "'>]+.(gif|jpg|jpeg|bmp|png))\2/i", $content, $matches)) { 
    $systeminfo['thumb'] = $matches[3][$auto_thumb_no]; 
   } 
  }

在这下面添加如下代码

//自动提取组图为缩略图 
  if(isset($_POST['auto_thumbp']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {   
   $pictureurls = $pictureurls ? $pictureurls : stripslashes($modelinfo['pictureurls']); 
   $auto_thumb_no = intval($_POST['auto_thumb_nop'])-1; 
   if(preg_match_all("/(=>)s([b"|']?)([^ "'>]+.(gif|jpg|jpeg|bmp|png))\2/i", $pictureurls, $matches)) { 
    $systeminfo['thumb'] = $matches[3][$auto_thumb_no]; 
   } 
  }

注意content_model.class.php文件有两片需要添加这个代码,一处是新增加文章的时候,一处是修改文章的时候!

好了可以自动提取组图的第N张图片为缩略图了!

缩略图是优先采用内容页的图片为缩略图,如果内容页无图片才会取组图的第N张为缩略图,这也是为什么组图字段提示的ID要多加一个P,不和内容页的一致,以及在添加在自动提取缩略图 下面的原因!

以上代码在黄页中是无效的,因为黄页是单独的文件!

返回顶部
顶部