【问题标题】:Problems with the Featured Image Size in WordpressWordpress 中的特色图片大小问题
【发布时间】:2014-11-29 14:32:41
【问题描述】:

This is the website where I'm trying the featured image on. 该网站使用wordpress。如您所见,图像使用自定义大小,而不是我希望它使用的大小。此外,它适用于自身的 .post img { } 特征。这里有我使用的代码。

(在 PHP 函数中):

if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size(640,205);

然后,在 HTML 中

<?php the_post_thumbnail();?>

我在 PHP 函数代码中写下了我想要的图像大小,但它不起作用!我做错了什么?

【问题讨论】:

    标签: php html css wordpress image


    【解决方案1】:

    您可以在使用时在 html 中设置图像大小,如下所示:

       <?php
       if ( has_post_thumbnail() ) {
            set_post_thumbnail_size( 640,205 );
            echo get_the_post_thumbnail( ); 
       }
       ?>
    

    如果你想在你的functions.php文件中为缩略图设置自定义值,你必须这样做:

     function mytheme_custom_thumbnail_size(){
        add_image_size( 'thumb-small', 200, 200, true ); // Hard crop to exact dimensions (crops sides or top and bottom)
        add_image_size( 'thumb-medium', 520, 9999 ); // Crop to 520px width, unlimited height
        add_image_size( 'thumb-large', 720, 340 ); // Soft proprtional crop to max 720px width, max 340px height
     }
    add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
    

    【讨论】:

    • 帖子中有特色图片吗?
    • 是的,但它以自定义尺寸显示。你可以在这里看到它:demilovatoonline.com/danithemes
    • 分享生成帖子列表的文件代码
    • 这是“主索引模板”代码 (pastebin.com/kx7C23Em);这是“主题功能”代码 (pastebin.com/JkLVd03n);这是定义特色图片样式的代码(pastebin.com/yFRfMnjk
    • 我没有看到我需要的所有代码.. 但已经知道另一种方法来完成它.. 添加:.post img { witdh: 640px; } 到你的 css 文件中,你就会得到你想要的结果..
    猜你喜欢
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2012-12-12
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 2018-05-24
    相关资源
    最近更新 更多