Use the_post_thumbnail as background image in LESS CSS [closed]

There’s nothing wrong with an inline style in this case – just set all your other rules in your LESS (like background position, repeat, size), and then in your template: <div class=”something”<?php if ( $id = get_post_thumbnail_id() ) { if ( $src = wp_get_attachment_url( $id ) ) printf( ‘ style=”background-image: url(%s);”‘, $src ); } ?>>

Getting featured image of particular size.

Please refer to the WP-Admin » Settings » Media. There you will find all the image sizes a theme creates. Basically the WordPress by default creates three sizes unless the Original: Large size (Default: 1024 x 1024) Medium size (Default: 300 x 300) Thumbnail size (Default: 150 x 150) From the admin panel you can … Read more

Better way to show Description and image Captions

There is nothing WordPress specific here, but you could make your code easier to read by removing the repeating parts. if ( $id = get_post_thumbnail_id() ) { $post = get_post( $id ); $data = array( $post->post_content, $post->post_excerpt ); // remove empty elements from array $data = array_map( ‘trim’, $data ); $data = array_filter( $data ); … Read more

Is it possible to add the_post_thumbnail to style.css?

If you want to add background image you can do inline css in html PHP: <?php if(has_post_thumbnail()) { $desktop_src = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘desktop’); $ipad_src = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘ipad’); $mobile_src = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘mobile’); $desktop = ‘style=”background: url(‘.$desktop_src[0].’);”‘; $ipad = ‘style=”background: url(‘.$ipad_src[0].’);”‘; $mobile=”style=”background: url(“.$mobile_src[0].’);”‘; } ?> HTML: <div id=”desktop” <?php echo $desktop; ?>></div> <div id=”ipad” <?php echo $ipad; ?>></div> … Read more

how to resize thumbnail image

First of all: add_image_size() is to ADD a new image size into your WordPress installation. Now, as you said: I just want to resize my Image You need to enter into your wp-admin panel. Then Settings » Media, and change the thumbnail size there. Just change the thumbnail size there. Now use the plugin: Regenerate … Read more

Assign SQL ‘post_thumbnail’ column as featured image

How is the post_thumbnail information stored? If you’ve already created an attachment with the image and are storing the attachment’s postId in post_thumbnail, then you just need to go through your posts and update the meta using update_post_meta($postId, ‘_thubmnail_id’, $attachmentPostId). If post_thumbnail stores the path to an image file on your server, you need to … Read more