在wordpress中获取图像标题和描述属性

时间:2017-05-24 07:50:07

标签: php html wordpress

我已查阅了所有网页,但没有任何结果对我而言。我想要做的是获取您在媒体库中提供的附加图像的标题和说明,其中您还有标题,替代文字和说明。我希望该标题在html中的title属性中显示如下:

<a href="http://somelink.com/" title="here i want to fetch that title">

修改 请记住,我想在这里输出一个画廊短代码。

修改 这是视觉编辑器中短代码的完整输出

public function vc_gallery_html( $atts, $content = null) {        

        //Get and extract shortcode attributes
        $atts = vc_map_get_attributes( 'vc_gallery', $atts);
        extract( $atts );

        //Design options
        $wrapper_classes = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_custom_css_class( $css, ' ' ), 'vc_gallery', $atts );

        if (!empty($gallery_duration)) {
            $gallery_duration_html = $gallery_duration;
        }else{
            $gallery_duration_html = '600';
        }

        if (!empty($gallery_delay)) {
            $gallery_delay_html = $gallery_delay;
        }else{
            $gallery_delay_html = '0';
        }

        if ($gallery_spacing == '0px') {
            $parent_margin_css = '0px';
            $child_padding_css = '0px';
        }
        if ($gallery_spacing == '5px') {
            $parent_margin_css = '-2.5px';
            $child_padding_css = '2.5px';
        }
        if ($gallery_spacing == '10px') {
            $parent_margin_css = '-5px';
            $child_padding_css = '5px';
        }
        if ($gallery_spacing == '15px') {
            $parent_margin_css = '-7.5px';
            $child_padding_css = '7.5px';
        }
        if ($gallery_spacing == '30px') {
            $parent_margin_css = '-15px';
            $child_padding_css = '15px';
        }
        if ($gallery_spacing == '50px') {
            $parent_margin_css = '-25px';
            $child_padding_css = '25px';
        }

        if ($gallery_masonry == 'yes') {
            $gallery_masonry_class = 'masonry';
        }else{
            $gallery_masonry_class = '';
        }

        $html = '';

        if ($gallery_lightbox == 'yes') {
        }

        $html .= '
            <div class="sp-gallery ' . $gallery_columns . ' '. $wrapper_classes .' '. $gallery_masonry_class .'" data-aos="'. $gallery_animation .'" data-aos-delay="'. $gallery_delay_html .'" data-aos-duration="'. $gallery_duration_html .'" data-aos-once="true" style="margin: '. $parent_margin_css .';">';

            $gallery_images_array = explode(',', $gallery_images);

            foreach ($gallery_images_array as $image_id) {

                if ($gallery_columns == 'column1') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = aq_resize( $img_url, 1100, 1100, true, true, true ); //resize & crop img
                }
                if ($gallery_columns == 'column2') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = aq_resize( $img_url, 750, 750, true, true, true ); //resize & crop img
                }
                if ($gallery_columns == 'column3') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = aq_resize( $img_url, 570, 570, true, true, true ); //resize & crop img
                }
                if ($gallery_columns == 'column4') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = aq_resize( $img_url, 475, 475, true, true, true ); //resize & crop img
                }
                if ($gallery_columns == 'column5') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = aq_resize( $img_url, 320, 320, true, true, true ); //resize & crop img
                }
                if ($gallery_columns == 'column6') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = aq_resize( $img_url, 285, 285, true, true, true ); //resize & crop img
                }
                if ($gallery_masonry == 'yes') {
                    $img_url = wp_get_attachment_url( $image_id ); //get img URL   
                    $image = $img_url;
                }

                $thumb_img = get_post( get_post_thumbnail_id() );

                $html .= '<a href="'. $img_url .'" class="gallery-item" style="padding: '. $child_padding_css .';" title="'. $thumb_img->post_content .'">';
                    $html .= '<img src="' . $image . '" style="border-radius: '. $gallery_radius .';">';
                $html .= '</a>';
            }

        $html .= '</div>'
        ;

        return $html;

    } 

}

0 个答案:

没有答案