【发布时间】:2016-03-14 13:16:41
【问题描述】:
我有一个脚本,它根据带有标题的简码捕获帖子中的所有图像,并将图像和标题输出到轮播
这就是短代码的样子:
[caption id="attachment_52788" align="alignnone" width="435" caption="my caption"]<a href="#"><img src="image.jpg" alt="" title="my title" width="435" height="363" class="size-full wp-image-52788" /></a>[/caption]
这是提取标题和图像的 php 代码
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$output2 = preg_match_all('/caption="(.*?)"/', $post->post_content, $matches2);
$gallery = $matches[1];
$captions = $matches2[1];
$count_of_captions = 0;
foreach ($captions as $capt) {
$js .= 'captions[' . $ii . '] = "' . $capt . '";' . "\n";
$ii++;
if ($capt != "") {
$count_of_captions++;
}
}
所有这些都适用于旧的 wordpress 版本。现在 wordpress 以这种方法输出标题:
[caption id="attachment_52725" align="alignnone" width="440"]<img class="size-full wp-image-52725" src="image.jpg" alt="" height="347" /> my caption[/caption]
现在标题在图片标签之后。现在如何提取字幕?
【问题讨论】:
标签: wordpress