朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

WordPress成功调用多张文章缩略图的教程

最近本站在我们QQ教程群里看到一个有一个伙伴一直在问如何调用文章内多张图片做文章缩略图,一直没人回复。

本站本着助人为乐的精神帮他搜了搜,网上的相关wordpress教程大多都是过期了不能使用的,经过本站研究,终于找到一种成功调用文章多张缩略图的wordpress教程,其实也很简单,把网上错误的教程修改下就可以了。

实现代码

/*
 * wordpress调用多张文章图片缩略图
 * 本站(zhuchunshu.com)整理
 */
function preview_img($soContent) {
	$soImages = '~]* />~';
	preg_match_all( $soImages, $soContent, $thePics );
	$allPics = count($thePics);
	if( $allPics > 0 ) { 
		$count=0;
		foreach($thePics[0] as $v) {
			if( $count == 5 ) {break;} //图片数量,自行调整
			else { echo '',$v,''; }
			$count++;
		}
	}
}

使用教程

首先将上面代码放到主题模板函数 functions.php 中,然后在文章列表循环内使用下面代码调用文章多张缩略图。

post_content);?>

文章来源于互联网:wordpress成功调用多张文章缩略图的教程

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » WordPress成功调用多张文章缩略图的教程

评论 48

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #60

    Thanks for revealing your ideas in this article. The other element is that each time a problem arises with a pc motherboard, folks should not consider the risk associated with repairing it themselves because if it is not done right it can lead to irreparable damage to an entire laptop. It is usually safe to approach your dealer of any laptop for the repair of the motherboard. They’ve already technicians with an expertise in dealing with notebook computer motherboard problems and can make the right diagnosis and conduct repairs.

  2. #59

    Thanks for your text. I would also love to say a health insurance broker also works well with the benefit of the actual coordinators of your group insurance policies. The health broker is given a summary of benefits needed by a person or a group coordinator. What any broker may is hunt for individuals as well as coordinators that best match up those wants. Then he presents his referrals and if both parties agree, this broker formulates a legal contract between the two parties.

  3. #58

    Hiya, I am really glad I’ve found this info. Nowadays bloggers publish just about gossips and internet and this is really frustrating. A good blog with interesting content, this is what I need. Thanks for keeping this web-site, I will be visiting it. Do you do newsletters? Can’t find it.