Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Redux框架:获取图像库标题_Php_Wordpress_Frameworks_Gallery_Redux Framework - Fatal编程技术网

Php Redux框架:获取图像库标题

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

我需要得到所有图片的标题,我上传到画廊与redux

这是具有redux框架的主题选项中的代码:

我试图在WordPress网站上显示标题,该代码仅用于测试:

<?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; ?>