pull out images in wordpress post

2019-08-30 18:42发布

Looking to automatically separate the images and text from my wordpress post <?php the_content(); ?> so I can put them in two different locations.

Not sure the best method to do this but have tried preg_replace approach but cant seem to figure out the right input

<?php
 // get the content
 $block = get_the_content();

 // check and retrieve blockquote
if(preg_match ... 

?>

标签: php wordpress
2条回答
一夜七次
2楼-- · 2019-08-30 19:00

It's answered here on wordpress.stackexchange.

$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", " ", $content);          
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

To get the images from the inline post content this article will help.

preg_match('#(<img.*?>)#', $content, $results);
查看更多
The star\"
3楼-- · 2019-08-30 19:18

You need to build a new function with the_content() to filter media and string from post content.

To do it, You should to know php well.

查看更多
登录 后发表回答