Kesar Sisodiya
Kesar Sisodiya

Reputation: 1624

How to get wordpress featured image in href tag

I have created a custom post type, which is poping up through a plugin. But image is not showing up in popup so I want to call image in href tag and i don't know how to call it.

There some codes

<?php
    $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title"" rel="lightbox" href="#" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;
    ?>

Upvotes: 0

Views: 1907

Answers (4)

Pranita
Pranita

Reputation: 1325

<?php 
    $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title"" rel="lightbox" href="'.$large_image_url[0].'" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;
?>

Replace this code.

Upvotes: 2

Mitul Shah
Mitul Shah

Reputation: 1566

Use wp_get_attachment_image_src to get image url

<?php 
 $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 

    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title="" rel="lightbox" href="$image" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;

?>

Upvotes: 0

Nurdin
Nurdin

Reputation: 23883

your title tag maybe ?

change title"" to title=""

<?php
    $args = array( 'post_type' => 'Gallery', 'posts_per_page' => All );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    echo '<div class="thumbnail-container"><div class="thumbnail-wrap"><a title="" rel="lightbox" href="#" >';
    the_post_thumbnail(full);
    echo '</a><div class="thumbnail-containt">';
    the_content();
    echo '</div></div></div>';
    endwhile;
    ?>

Upvotes: 0

Ram Sharma
Ram Sharma

Reputation: 8809

I feel your should try

$imageUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
<img src="<?php echo $imageUrl; ?>" />

Upvotes: 0

Related Questions