【问题标题】:I can't retrieve featured image url through wordpress我无法通过 wordpress 检索特色图片网址
【发布时间】:2016-02-01 05:09:35
【问题描述】:

所以我试图将图像调用到我的主页(主页)。该图像存在于帖子中,并被设置为该帖子的特色图像。所以我得到了帖子 ID,我能够在首页上显示标题和内容。但是特色图片不会显示网址。

所以这是我在首页上的代码:

<?php
$post_id = 53;
$queried_post = get_post($post_id);
$title = $queried_post->post_title; 
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id));
echo $title;
echo $image;
echo $queried_post->post_content;
?>

它只是输出数组。谢谢你的帮助。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    这里是您的问题的解决方案。

    $post_thumbnail_id = get_post_thumbnail_id($post_id);
    $thumb_images = wp_get_attachment_url($post_thumbnail_id);
    echo $thumb_images;
    
    //Here you will get url of featured image.
    

    【讨论】:

      【解决方案2】:

      以下代码可以帮助您解决问题。

      $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ); // get array of featured image
      
      echo $image[0]; //get url of featured image of post
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-04
        • 2015-07-16
        • 2012-09-27
        • 2013-03-13
        • 2018-11-19
        • 1970-01-01
        • 2020-01-15
        • 2021-11-01
        相关资源
        最近更新 更多