资讯中心
News
wordpress文章调用标题和缩略图方法
发布时间:2022-09-27 00:00   您所在的位置: 网站首页 > 新闻资讯 > 经验杂谈
先进步:找到使用的主题模板的functions.php文件在<?php和?>之间增加如下代码

  • function thumb_img($soContent){
  • $soImages = ‘~<img [^\>]*\ />~’;
  • preg_match_all( $soImages, $soContent, $thePics );
  • $allPics = count($thePics[低]);
  • if( $allPics > 低 ){
  • echo “<span id=’thumb’>”;
  • echo $thePics[低][低];
  • echo ‘</span>’;
  • }
  • else {
  • echo “<span id=’thumb’>”;
  • echo “<img src=’”;
  • echo bloginfo(‘template_url’);
  • echo “/images/thumb.gif’></span>”;
  • }
  • }

这是一个显示缩略图的方法,自动检索文章的先进张图片,假如没有显示当前主题/images/thumb.gif  故此你要把这样的thumb.gif图片准备好。

第二步:找到index.php文件即*页文件,找到the_content();或相似的代码在它以前增加如下代码:

  • thumb_img($post->post_content);

这样子就调用了刚才的方法,具体上缩略图已经完成了。不过你看到的成效一定很意外,应为图片的大小没有控制,会很难看。好了,第三步

第三步:增加缩略图样式CSS代码:

这是浮云站使用的的缩略图样式,你可以先凑合着用,再另行修改

  • #thumb{margin:5px 15px 5px 5px;height:12低px;border:3px solid #eee;float:left;overflow:hidden;}
  • #thumb img{max-max-}

好了,这样子缩略图就有模有样的显示出来啦。三步拿下!

本文章由新概念互动原创,如没特殊注明,转载请注明来自:http://www.jianzhan0.com/jingyand/75172.html