帮杨林哥差资料的时候,发现另外一个wordpress获取文章内所有图片的办法

2015-05-20 1,169 1

首先在function.php里面写一个函数:

function all_img($soContent){
$soImages = '~<img [^\>]*\ />~';
preg_match_all( $soImages, $soContent, $thePics );
$allPics = count($thePics);
if( $allPics > 0 ){
foreach($thePics[0] as $v){
echo $v;
}
}
else {
echo "<img src='";
echo bloginfo('template_url');
echo "/images/thumb.gif'>";
}
}
register_nav_menus( array(
'primary' => __( 'Primary Navigation'),
));

 

 

需要调用的地方写:

<?php all_img($post->post_content);?>

 

 

相关文章

MySQL 设置优化记录
来自 WPJAM 的修改,给图片文件名增加时间戳
wordpress 博客使用 CloudFlare 的页面规则缓存设置教程
Better Search Replace – 简单强大易用的数据库替换工具
WordPress获取文章所有图片和图片数量
删除 WooCommerce 产品页中的简介 – Remove Woocommerce Product Short Description

评论(1)

发布评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据