Как извлечь alt прикрепленное изображение более коротким способом? - PullRequest
0 голосов
/ 17 января 2020

В настоящее время я извлекаю изображение пост-вложения (примечание: НЕ рекомендуемое изображение, а простое вложение img) следующим образом:

(functions.php файл)

function haruki($post_id) {
    global $post;
    $thumbnail_ID = get_post_thumbnail_id();
    $images = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
    if ($images) :
    foreach ($images as $attachment_id => $image) :
    if ( $image->ID != $thumbnail_ID ) :
    $img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); //alt
    if ($img_alt == '') : $img_alt = $image->post_title; endif;
    $big_array = image_downsize( $image->ID, 'large' );
    $img_url = $big_array[0];
    echo $img_url;
    endif; endforeach; endif; }

Затем вызывая его с <?php haruki("$post->ID"); ?>

Есть ли более короткий способ получить URL этого изображения?

Ссылка: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...