首页 文章

wordpress添加缩略图以发布摘录插件或方法

提问于
浏览
1

我正在寻找一种方法来添加缩略图图像以发布摘录 .

我已经安装了:SuperSlider-Excerpt和Thumbnail For Excerpts插件,但我需要专门指定我想要用于每个帖子的缩略图,或者自动获取要素图像以显示为缩略图 .

有人知道可以做到这一点的方法或插件吗?

2 回答

  • 2

    您可以使用Wordpress轻松完成此操作 . 就像Francy所说,the_post_thumbnail()会在admin部分的帖子编辑页面上添加您选择的精选图像 .

    首先,您需要在functions.php文件中设置缩略图 . 这是您主题的根目录(wp-content / themes / your-theme) . 写这个:

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 200, 200, false ); // Set your size, and clipping options
    

    这将使缩略图200x200 . 你可能想要别的东西,所以把你想要的任何数字放在那里 .

    现在缩略图处于活动状态,您可以在循环内的整个站点中使用the_post_thumbnail()来显示您选择的缩略图 .

    例如,如果您希望它们出现在索引页面上,请转到主题根目录中的index.php,然后再写入 . 试验这些出现的位置,并将它放在适合您的地方 .

  • 1

    在循环中尝试:

    the_post_thumbnail("thumbnail");
    

    或者对我有帮助的是:

    <?php
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail'); 
        $theImageSource = $image[0];
    ?>
    

相关问题