0

我正在将我的 WordPress 网站移动到一个新主题,新主题使用特色图片,而旧主题没有,因此我的旧帖子没有任何特色图片。现在我的网站上有超过 3000 个帖子,显然手动为它们设置特色图片是不可能的。

那么你们能帮我做一个 SQL 查询或将我链接到一些可以做到这一点的插件吗?

如果可以轻松满足这些要求,则有一些要求。首先,我希望将帖子的第一张图片设置为特色,而不是第一张“附加”图片。其次,查询或插件不应该对已经有特色图片的帖子做任何事情。

谢谢,

4

1 回答 1

0

之前的主题是怎么称呼特色图片的?现在大多数主题包括 add_theme_support('post-thumbnails')

你会想看看这个: https ://codex.wordpress.org/Post_Thumbnails

要在帖子中发布实际的特色图片,您需要对此进行调查。 https://codex.wordpress.org/Function_Reference/the_post_thumbnail

如果您想在内容顶部发布特色图片,请尝试此操作。 http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

我没有对此进行测试,但类似这样的东西可能会起作用。

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 );
于 2013-09-29T18:04:49.277 回答