How to get WordPress post featured image URL

前端 未结 20 1899
闹比i
闹比i 2020-12-02 04:59

I am using this function to get the featured images:


    


        
相关标签:
20条回答
  • 2020-12-02 05:10

    Easy way!

     <?php 
         wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()))
     ?>
    
    0 讨论(0)
  • 2020-12-02 05:11

    You can try this.

    <?php
       $image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    ?>
    <a href="<?php echo $image_url; ?>" rel="prettyPhoto">
    
    0 讨论(0)
  • 2020-12-02 05:12
    // Try it inside loop.  
    <?php
    $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    echo $feat_image;
    ?>
    
    0 讨论(0)
  • 2020-12-02 05:13

    You can try this:

    <?php 
        $feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
        echo $feat_image; 
    ?>
    
    0 讨论(0)
  • 2020-12-02 05:17

    Simply inside the loop write <?php the_post_thumbnail_url(); ?> as shown below:-

    $args=array('post_type' => 'your_custom_post_type_slug','order' => 'DESC','posts_per_page'=> -1) ;
    $the_qyery= new WP_Query($args);
    
    if ($the_qyery->have_posts()) :
        while ( $the_qyery->have_posts() ) : $the_qyery->the_post();?>
    
    <div class="col col_4_of_12">
        <div class="article_standard_view">
            <article class="item">
                <div class="item_header">
                    <a href="<?php the_permalink(); ?>"><img src="<?php the_post_thumbnail_url(); ?>" alt="Post"></a>
                </div>
    
            </article>
        </div>
    </div>            
    <?php endwhile; endif; ?>
    
    0 讨论(0)
  • 2020-12-02 05:20

    This perfectly worked for me:

    <?php echo get_the_post_thumbnail_url($post_id, 'thumbnail'); ?>
    
    0 讨论(0)
提交回复
热议问题