Adding featured image to posts created by a plugin

The quickest and dirtiest way to do this is to add one line to the insert_posts() function, just before the $imported++; line: } add_post_meta( $post_id, ‘raw_import_data’, json_encode( $twitter_raw ) ); // NEW LINE (change 1001 to the image ID): set_post_thumbnail( $post_id, 1001 ); $imported++; } This will obviously disappear if you ever update the plugin. … Read more

If no featured image, add one of the default images into DB

Im not sure about the random part. But to set a back up featured image if none is set just use <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { ?> <img src=”https://wordpress.stackexchange.com/questions/96146/<?php bloginfo(“template_directory’); ?>/images/default-image.jpg” alt=”<?php the_title(); ?>” /> <?php } ?> Or something like this without major template edits function autoset_featured() { global … Read more

Add title to image post

Sorry, but I don’t see any of those parameters in the parameter list for wp_get_recent_posts. $args = array( ‘numberposts’ => 10, ‘offset’ => 0, ‘category’ => 0, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘include’ => , ‘exclude’ => , ‘meta_key’ => , ‘meta_value’ =>, ‘post_type’ => ‘post’, ‘post_status’ => ‘draft, publish, future, pending, private’, ‘suppress_filters’ … Read more

Display post thumbnail for specific category outside the loop

Use get_the_post_thumbnail with a new WP_Query. <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘large’); echo ‘<a href=”‘ . $large_image_url[0] . ‘” title=”‘ . the_title_attribute(‘echo=0’) . ‘” >’; echo get_the_post_thumbnail($post->ID, ‘thumbnail’, array(‘class’ => ‘aligncentre’)); echo ‘</a>’; } ?>

Displaying and Querying Posts with Featured image

Start by cleaning up your code; $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘order’ => ‘asc’ ); $home_shows = new WP_Query($args); //setup your loop here if( $home_shows->have_posts() ): while( $home_shows->have_posts() ): $home_shows->the_post(); //fetch featured image if exists if ( has_post_thumbnail() ) { the_post_thumbnail(array(486,226)); } //fetch content the_content(); //etc… endwhile; endif; What output do … Read more

Add image size array to a portfolio thumbnail in combination with Masonry Jquery Plugin

the_post_thumbnail() only retrieves the specified thumbnail size for the current post. You’ll need to write a conditional function or use a custom query to randomize the posts shown or thumbnail sizes from your theme’s loop. If you are familiar with where your loop starts, then: $tile_sizes = array(‘small’,’medium’,’category-thumb’); LOOP STARTS $random_size = rand(0,2); $chosen_size = … Read more