如何在WordPress图库中的图片标题/描述之前自动显示图片标题?

时间:2020-08-31 作者:Waldemar

我正在使用一个简单的Wp 5。像这样的x库[库大小=“完整”列=“1”ID=“630463056306630763086309”]

gallery向我显示图像以及图像后的标题/描述。如何在此图像前自动插入/注入库图像标题?

请参见附加的图像示例

提前感谢wp 5.x gallery example

1 个回复
SO网友:SauRav

use this code in single.php

  $post->ID,
        \'post_type\' => \'attachment\',
        \'numberposts\' => -1,
        \'orderby\'        => \'title\',
        \'order\'           => \'ASC\',
        \'post_mime_type\' => \'image\',
    )))
    {
        foreach( $images as $image ) {
            $attachmenturl = wp_get_attachment_url($image->ID);
            $attachmentimage = wp_get_attachment_image_src( $image->ID, full );
            $imageDescription = apply_filters( \'the_description\' , $image->post_content );
            $imageTitle = apply_filters( \'the_title\' , $image->post_title );
            $i++;
            if (!empty($imageTitle)) {
                echo \' » \'.$imageDescription.\'\';
} else { echo \'\' ; }
        }
    } else {
        echo \'No Image Found\';
    }?>