问题描述:

I am moving my WordPress website to a new theme and the new theme uses featured images where as old one didnt hence my old posts dont have any featured images. Now there are over 3000 posts in my website and obviously setting featured images for them manually is kind of impossible.

So can you guys help me make an SQL query or link me to some plugin which can do this?

There are a few requirements if these can be fulfilled easily. First of all, I want the first image of the post to be set as featured not the first 'attached' images. Secondly, the query or plugin shouldnt do anything to posts which already have featured images.

Thanks,

网友答案:

How did the previous theme call the featured image? Most themes these days include the add_theme_support( 'post-thumbnails' )

You'll want to look into this: https://codex.wordpress.org/Post_Thumbnails

To post the actual Featured Image inside the post, you'll want to look into this. https://codex.wordpress.org/Function_Reference/the_post_thumbnail

If you're looking to post a featured image at the top of the content, try this. http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

I have not tested this but something like this might work.

function my_the_content_filter( $content ) {
 if ( has_post_thumbnail()) {
   $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
   echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
   the_post_thumbnail('large');
   echo '</a>';
   // Returns the content.
   return $content;
 }
add_filter( 'the_content', 'my_the_content_filter', 10 );
相关阅读:
Top