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

首先在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);?>

 

 

Share

小 虾

哦也,我是小虾

You may also like...

1 Response

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.