微信采集器采集到了文章后,进行发布后发现前台网页无法显示缩略图。这是怎么回事呢?
首先软件有提取缩略图的功能,但是相对于网站系统不同,wordpress和discuz是没有单独发布缩略图进去网站里的。那么怎么解决呢?
WordPress是需要上传后才可以设置特色图片,而孤狼微信采集器并没有上传功能。这样一来就得借助第三方插件,插件简单一些,会自动提取。或者自己在fountions.php里面去写提取图片的函数了,写法可以百度:WordPress如何文章提取图片做缩略图,有很多的写法,其实就是正则表达式提取出所有图片,过滤小图片,然后随机一张图片来做缩略图。
提取缩略图代码:(大前端主题)
1.打开大前端主题的functions.php文件,添加代码:
//缩略图获取 function thumb_img($soContent){ $soImages = '~<img [^\>]*\ />~'; preg_match_all( $soImages, $soContent, $thePics ); $allPics = count($thePics[0]); $site = get_permalink(); if( $allPics > 0 ){ echo "<div class='wpztw_thumbnail'>"; echo '<a href="'.$site.'">'; echo $thePics[0][0]; echo '</a>'; echo "</div>"; }else { $random = mt_rand(1, 10);//随机取10张内的任意一张。 echo '<div class="wpztw_thumbnail"><a href="'.$site.'"><img src="'.get_bloginfo('template_url').'/img/random/tb'.$random.'.jpg" alt="'.trim(strip_tags( $post->post_title )).'" /></a></div>'; } }
2.大前端主题的缩略图代码位于主题的excerpt.php文件中的第12行
if (_hui("list_type") !== "text") { //echo "<a" . _post_target_blank() . " class=\"focus\" href=\"" . get_permalink() . "\">" . _get_post_thumbnail() . "</a>"; //注释掉这行,下面添加一句 echo "" . thumb_img($post->post_content) . ""; } echo "<header>";
3.添加缩略图样式
/* 缩略图功能 */ .wpztw_thumbnail img { float: left; width: 220px; height: 150px; display: table-cell; vertical-align: middle; margin-left: -236px; }
4.软件上勾选,文章前插入缩略图
discuz则是发布文章的位置没有缩略图这个参数可填,而唯一的缩略图是上传图片才可以使用作为缩略图,软件也没有上传机制,这样就又得重新写提取文章里图片作为缩略图了。
当然如果你比较了解程序代码和数据库,你可以用孤狼公众号助手里的MySQL或者自定义API的功能来写进数据库,变量名称是{image},调用进去数据库这样就有缩略图了。做法比较复杂,但是很有效果。
未经允许不得转载:www.gulangu.com孤狼工作室 » 网站运营版-发布时文章没有缩略图怎么办?