获取wordpress图片的具体title属性

get the specific title attribute of wordpress image

请问如何从wordpress media获取wordpress图片的具体title属性?

上传图片时输入的信息 life, title, alt captions, description.

这应该对你有帮助。

$title = get_post(get_post_thumbnail_id())->post_title; // Title
$caption = get_post(get_post_thumbnail_id())->post_excerpt; // Caption
$description = get_post(get_post_thumbnail_id())->post_content; // Description

您可以找到 wordpress 图片附件的特定属性。

   <?php 
    $attachment_id = 8; // attachment ID

    $image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
    if( $image_attributes ) {
    ?> 
    <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
    <?php } ?>

    An array containing: 

    [0] => url
    [1] => width
    [2] => height
    [3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.