WordPress缩略图大小

szqfcxe2  于 2023-01-08  发布在  WordPress
关注(0)|答案(3)|浏览(272)

I am having a problem at the site ivanschneider.de regarding the thumbnails for the posts.
我想拥有650 x 0像素的大缩略图,所以我在k2-loop.php中添加了以下代码:

<div class="entry-content">
        <?php if ( function_exists('has_post_thumbnail') and has_post_thumbnail() ): ?>
            <a href="<?php the_permalink(); ?>">
            <?php the_post_thumbnail( array( 650, 0 ), array( 'class' => 'alignleft' ) ); ?></a>
        <?php endif; ?>

    </div><!-- .entry-content -->

现在,这是工作。每当我去WordPress的 Jmeter 板,并设置一个新的图像作为文章缩略图,它生成650 x 0的图像,并正确显示它。
但是我使用了另一个插件,叫做相关帖子缩略图,它显示一些缩略图/链接到其他相关帖子。因为我没有设置小缩略图,它显示那些650像素的大图片的缩略图很小,不成比例,看起来很难看。
所以,我去了媒体库的选项,并设置缩略图大小为150 x 150像素,有一些插件这样的缩略图。我想,它会创建他们,让我的帖子缩略图在和平。
现在我的问题是:这似乎覆盖了我在k2-loop.php中输入的代码。换句话说,当我想创建一个新帖子并将一个图像设置为帖子缩略图时,会得到150 x 150的小尺寸,而不是我在k2-loop.php中设置的650 x 0的尺寸。
如何防止k2-loop.php代码被媒体集缩略图设置覆盖?
先谢谢你了。
亲切问候

njthzxwz

njthzxwz1#

我解决这个问题的方法是

<?php the_post_thumbnail( medium ); ?></a>"

而不是具有650 × 0的阵列。

hi3rlvi2

hi3rlvi22#

<?php
        $args = array(
            'post_type' => 'news', // custom post type
            'orderby' => 'ID',  // order by ID
            'order' => 'DESC',   
            'posts_per_page' => -1
          
        );
        $the_query = new WP_Query($args);
        
        if( $the_query->have_posts() ) : ?>

        <?php while( $the_query->have_posts() ) : $the_query->the_post(); 
   
        $post_image_id = get_post_thumbnail_id($post_to_use->ID);

        if ($post_image_id) {$thumbnail = wp_get_attachment_image_src( $post_image_id,array(150,150));
        if($thumbnail) (string)$thumbnail = $thumbnail[0];} 
        ?>
        
        <img src="<?php echo $thumbnail;?>" >

      <?php else:  ?>
      <p>
      <?php _e( 'Sorry, no posts matched your criteria.' ); ?>
      </p>
      <?php endif; ?>
a0x5cqrl

a0x5cqrl3#

//Default WordPress

Thumbnail Sizes

The default image sizes of WordPress are “thumbnail”, “medium”, “large” and “full” (the size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under Settings > Media. This is how you can use these default sizes with the_post_thumbnail():


the_post_thumbnail( 'thumbnail' );     // Thumbnail (150 x 150 hard cropped)
the_post_thumbnail( 'medium' );        // Medium resolution (300 x 300 max height 300px)
the_post_thumbnail( 'medium_large' );  // Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
the_post_thumbnail( 'large' );         // Large resolution (1024 x 1024 max height 1024px)
the_post_thumbnail( 'full' );          // Full resolution (original size uploaded)
 
//With WooCommerce
the_post_thumbnail( 'shop_thumbnail' ); // Shop thumbnail (180 x 180 hard cropped)
the_post_thumbnail( 'shop_catalog' );   // Shop catalog (300 x 300 hard cropped)
the_post_thumbnail( 'shop_single' );    // Shop single (600 x 600 hard cropped)

the_post_thumbnail( array(100,100) );   // custom size add in array.

Register new image sizes for Post Thumbnails with: add_image_size().
To set the default size for Post Thumbnails see: set_post_thumbnail_size().

相关问题