【问题标题】:get the specific title attribute of wordpress image获取wordpress图片的具体title属性
【发布时间】:2015-07-24 02:29:00
【问题描述】:

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

上传图片时输入的信息,包括生活、标题、替代标题、描述。

【问题讨论】:

    标签: php wordpress image media


    【解决方案1】:

    这应该对你有帮助。

    $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
    

    【讨论】:

    【解决方案2】:

    你可以找到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.
    

    【讨论】:

      猜你喜欢
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      相关资源
      最近更新 更多