我正试图从我的WordPress帖子的内容中“提取”这些图片。我将它们与文本放在管理面板的内容中。当输出时,它们被包装在<p>
标记中。我想把它们拉出来,这样我就可以把它们包装在我自己的自定义标签中(所以我可以独立地使用CSS和<p>
)。
我有下面的代码,它提取了块引号,不知道如何重写它来提取图像。
<div class="block-pull">
<?php
// get the content
$content = get_the_content();
// check and retrieve blockquote
if(preg_match('~<blockquote>([\s\S]+?)</blockquote>~', $content, $matches))
// output blockquote
echo $matches[1];
?>
</div>
我想把图片放在我的页面上的另一个地方,把文字放在其他地方。我现正将他们带进来:
<?php the_content(); ?>
发布于 2015-06-02 02:57:11
仅从内容中获取和显示图像:
preg_match_all('/(<img [^>]*>)/', get_the_content(), $images);
for($i=0; isset($images[1]) && $i < count($images[1]); $i++) {
echo $images[1][$i];
}
若要显示没有任何图像的内容,请执行以下操作。
$content = preg_replace('/(<img [^>]*>)/', '', get_the_content());
$content = apply_filters('the_content', $content);
echo $content;
https://stackoverflow.com/questions/30586267
复制相似问题