拉出wordpress帖子中的图片 [英] pull out images in wordpress post
本文介绍了拉出wordpress帖子中的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望从我的 wordpress 帖子中自动分离图像和文本 <?php the_content();?>
这样我就可以将它们放在两个不同的位置.
Looking to automatically separate the images and text from my wordpress post <?php the_content(); ?>
so I can put them in two different locations.
不确定执行此操作的最佳方法,但尝试过 preg_replace 方法但似乎无法找出正确的输入
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 ...
?>
推荐答案
$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);
这篇关于拉出wordpress帖子中的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文