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

How can I list posts with different formats depending on order?

WP_Query will track which post is current. For example: $p = new WP_Query(array(‘post_type’=>’post’,’posts_per_page’=> 10)); if ($p->have_posts()) { while ($p->have_posts()) { $p->the_post(); echo $p->current_post.'<br>’; } } You could use that to selectively format your posts. For example $p = new WP_Query(array(‘post_type’=>’post’,’posts_per_page’=> -1)); if ($p->have_posts()) { while ($p->have_posts()) { $p->the_post(); switch ($p->current_post) { case 0: case 3: … Read more

get_the_post_thumbnail($post->ID, ‘thumbnail’); not working. How can I solve this?

The problem of showing the thumbnail twice is because of your the_content(); which is defined in the content-page.php file that has the line the_post_thumbnail(); that will get the featured image. so intead of using the the_content() just use the get_the_content() function to get only the content without the featured image. Let me know if that … Read more