Php Redux框架:获取图像库标题
我需要得到所有图片的标题,我上传到画廊与redux 这是具有redux框架的主题选项中的代码: 我试图在WordPress网站上显示标题,该代码仅用于测试:Php Redux框架:获取图像库标题,php,wordpress,frameworks,gallery,redux-framework,Php,Wordpress,Frameworks,Gallery,Redux Framework,我需要得到所有图片的标题,我上传到画廊与redux 这是具有redux框架的主题选项中的代码: 我试图在WordPress网站上显示标题,该代码仅用于测试: <?php $attachmentIds = explode(',', $redux_demo['opt-gallery']); foreach($attachmentIds as $attachmentId): $metaAttachment = wp_get_attachment_metadat
<?php
$attachmentIds = explode(',', $redux_demo['opt-gallery']);
foreach($attachmentIds as $attachmentId):
$metaAttachment = wp_get_attachment_metadata( $attachmentId );
echo '<pre>';
print_r( $metaAttachment );
echo '</pre>';
?>
但是,此代码返回我[caption]=>空
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
标题字段有一个值,但redux似乎没有保存信息,或者我的代码错误?这是我一直在寻找的解决方案: 在functions.php文件中: 在模板文件中: 我希望有帮助!:-
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
<?php
global $redux_demo;
$myGalleryIDs = explode(',', $redux_demo['opt-gallery']);
foreach($myGalleryIDs as $myPhotoID):
$photoArray = wp_get_attachment($myPhotoID);
?>
<a href="<?php echo wp_get_attachment_url( $myPhotoID ); ?>" class="lightbox" title="<?php echo $photoArray[caption]; ?>">
<img src="<?php echo wp_get_attachment_url( $myPhotoID ); ?>" class="img-rounded" alt="<?php echo $photoArray[title]; ?>">
</a>
<?php endforeach; ?>