我使用函数提取了figcaption标签中的数据,$position代表当前图像的索引。
function getImageCaption($postID, $position){
$post_id = $postID;
// get the post object
$post = get_post( $post_id );
// we need just the content
$content = $post->post_content;
// we need a expression to match things
$regex = \'/<figcaption>(.*)<\\/figcaption>/\';
// we want all matches
preg_match_all( $regex, $content, $matches );
// reversing the matches array
$matches = array_reverse($matches);
// we\'ve reversed the array, so index 0 returns the result
foreach ($matches as $key => $value) {
return $value[$position];
}
}