2015-05-13 2 views

ответ

0

Вы можете найти определенный атрибут прикрепления изображения 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. 
0

Это должно вам помочь.

$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 
+0

Hai Ferrrmolina Я пробовал использовать заголовок $, но заголовок сообщения появляется, а не название конкретного изображения из медиа-библиотеки. – njhelloworld

+0

Я увидел код из http://wordpress.stackexchange.com/questions/185396/getting-the-image-title-alt-attribute-from-the-gallery-shortcode , но он выводит пустой. – njhelloworld

+0

Посмотрите, что: http://www.bobz.co/how-to-get-attachment-image-caption-alt-or-description/ – Ferrrmolina

Смежные вопросы