get_the_post_thumbnail wordpress 3.5

I could be mistaken, but I don’t think $post->post_id works to retrieve the post’s ID. I believe you want $post->ID. So that was probably your issue to begin with, though without seeing your $attr array, it’s hard to say. Here’s a reference for $post‘s properties. In this case, get_the_post_thumbnail is the more appropriate function. In … Read more

Child Category Image

You can get a random post by category by using the following code: query_posts( array ( ‘showposts’ => 1, ‘orderby’ => ‘rand’, ‘cat’ => $cat->term_id ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); … And then use get_the_post_thumbnail() to retrieve the post featured image: if ( has_post_thumbnail() ) $image = … Read more

Getting img src from thumbnail_id using javascript

I haven’t tested this, but you’ll probably get the gist of it anyway: add_action(‘wp_enqueue_scripts’, ‘send_image_source_to_js’); function send_image_source_to_js() { global $post; // Does this post have a featured image? If yes, fetch the link / source $has_image = $source = false; if($thumb_id = get_post_thumbnail_id($post->ID)) { $has_image = true; $source_array = wp_get_attachment_image_src($thumb_id, array(300,300)); $source = $source_array[0]; } … Read more

Height and width attribute not setting by the_post_thumbnail

In the 2nd attribute of the_post_thumbnail() you can give additional attributes for the image. the_post_thumbnail( ‘postbox-thumb’, array( ‘width’ => 100, ‘height’ => 100 ) ) I’ve just checked it again the width and height are set in the latest WP Versions, so you might have just to update your WordPress installation.

Title on hovering on the featured image

Alternative approach: <li class=”cycle-item slide-<?php echo $i; ?>”> <span class=”featured-title”><?php the_title(); ?></span> <a href=”https://wordpress.stackexchange.com/questions/97055/<?php the_permalink();?>”><?php the_post_thumbnail(‘featured’); ?></a> </li> then hide the span with CSS, show it on hover of the <li> element, position it over the image with CSS. Example: li.cycle-item { position: relative; } li.cycle-item .featured-title { display: none; } li.cycle-item:hover .featured-title { display: … Read more

Retrieve Image Attachments Getting Post Thumbnail Image First

First, exclude the featured image (= post thumbnail) from the query, then set up the posts array as combination of the featured image and the other images. Put this directly below $args = … and above $attachments = …: if (has_post_thumbnail($post->ID)) { $featured_image = get_post_thumbnail_id($post->ID); $args[‘exclude’] = $featured_image; $attachments = array(get_post($featured_image)) + get_posts($args); } else

Add Image Size for Featured Image with Responsive Design

You can wrap the image in a figure. <!– html –> <figure class=”constrained-container”> <img src=”https://wordpress.stackexchange.com/questions/100091/my-image.jpg” alt=”What my image is about”/> </figure> Then style the figure as well as the image. /* css */ .constrained-container { height: 300px; overflow: hidden; /* this hides excess of the image */ } .constrained-container img { display: block; width: 100%; … Read more