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

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

images not showing despite using add_theme_support(‘post-thumbnails’);

Since you appear to be using Featured Images, replace this: <div class=”post-image”> <?php echo ravs_get_custom_image( get_post_thumbnail_id () ); ?> </div><!– end post-image –> with this: <div class=”post-image”> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( ‘custom-image’ ); } ?> </div> References Codex: has_post_thumbnail() the_post_thumbnail()

Choose to Display Post Thumbnail?

This is modified code from twentyten that does what you’re looking for. Put this in header or wherever you want the image to run. See string post-thumbnail — that is size. Make sure it is defined as 940 x 180 in functions.php if ( is_singular() && current_theme_supports( ‘post-thumbnails’ ) && has_post_thumbnail( $post->ID ) && ($image … Read more

Show posts image attachments

See the below code. <?php $args = array( ‘posts_per_page’ => -1, ‘order’=> ‘DESC’, ‘orderby’ => ‘date’ ); $postslist = get_posts( $args ); foreach ( $postslist as $post ) : setup_postdata( $post ); ?> <div> <?php $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ =>’any’, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); … Read more

Problem with showing featured image

Use an is_single() condition to ensure the thumbnail isn’t added on archive pages. You should also be using get_the_post_thumbnail and prepending it to $content, rather than just echo’ing it out: function put_thumbnail_in_posting( $content ) { if ( is_single() && has_post_thumbnail() && get_post_type() == ‘post’ ) { $thumbnail = get_the_post_thumbnail( null, ”, array( ‘style’ => implode( … Read more