• I need to get the url of a thumbnail to create a link.

    this is what happen:

    I have set some thumbnail size in my function php like this:

    add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 226, 135 );
    	add_image_size( 'gallery-link', 96, 60, true ); gallerie
    	add_image_size( 'gallery-preview', 400, 350, true );
    	add_image_size( 'gallery-full', 900, 9999, false );

    then I have a page with a custom loop:

    <?php $preview_img = new WP_Query('post_type=pictures&posts_per_page=18'); ?>
    <?php while ($preview_img->have_posts()) : $preview_img->the_post(); ?>

    an inside the loop I want to link the medium thumbnail to the large one so that cicking on the first the second will be opened in a shadowbox:

    <a href="<?php echo get_post_meta($post->ID, 'gallery-full' , true); ?>" rel="shadowbox">
    <?php the_post_thumbnail('gallery-preview'); ?>
    </a>

    now I’m gettin the medium picture “gallery-preview” but in the generated html it links to nothing, this is what i can see in the page source:

    <a href="" rel="shadowbox"><img src=".. etc

    why the href is empty??

    I have tested to echo the $post->ID and it works giving the correct post ID.
    what am I doing wrong??

    (the strange thing is that I’m using the exact same code in another blog and it works there…)

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi-

    I am having the same problem.. I want to use the featured image URL, but I don’t want to dive into all the mess to get it.

    I think I am going to use the hack I came up with. Its not pretty but it gets the job done:

    $a=get_the_post_thumbnail();
                preg_match_all('/src=".*?"/',$a,$matches);
                echo $matches[0] [0];

    Actually,

    I think this works better:

    $featured_img=explode('www', get_attached_file(get_post_thumbnail_id()));
    $featured_img=get_bloginfo('url') . $featured_img[1];

    Execute the code inside the loop.

    Thread Starter misthero

    (@misthero)

    if you have something like this:

    add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 226, 135 );
    	add_image_size( 'gallery-link', 96, 60, true ); gallerie

    you can use inside your loop:

    <!-- get url for thumbnail gallery-link -->
    <?php $galleryurl = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'gallery-link' ); ?>

    and use it like this:
    <a href="<?php echo $galleryurl[0]; ?>" > link </a>

    srichand

    (@srichand)

    Hi misthero,

    The code did the work , thanks man.

    @misthero thank you very much

    Hi,

    I am using a WP theme that has featured tabs
    (https://www.elegantthemes.com/preview/MyProduct/) those 3 grey tabs show featured content, but the featured image on those tabs comes from the wodpress featured image.

    I want the featured image to come from a get_post_meta like the tab tittle, but i am not sure on how to chnage the code… can anyone help me?

    $arr[$i]["tabtitle"] = get_post_meta($post->ID, 'Tab', $single = true);
    		$arr[$i]["permalink"] = get_permalink();
    
    		$arr[$i]["thumbnail"] = get_thumbnail($width,$height,'thumbnail alignleft',$arr[$i]["fulltitle"],$arr[$i]["tabtitle"]);
    		$arr[$i]["thumb"] = $arr[$i]["thumbnail"]["thumb"];
    		$arr[$i]["use_timthumb"] = $arr[$i]["thumbnail"]["use_timthumb"];
    
    		$i++;
    		$ids[]= $post->ID;
    	endwhile; wp_reset_query();	?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘can't get featured image url using get_post_meta’ is closed to new replies.