PHP Wordpress后缩略图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Wordpress后缩略图相关的知识,希望对你有一定的参考价值。

// Enable support for post-thumbnails  
      
add_theme_support('post-thumbnails');  
      
    // If we want to ensure that we only call this function if  
    // the user is working with WP 2.9 or higher,  
    // let's instead make sure that the function exists first  
      
if ( function_exists('add_theme_support') ) { 
     add_theme_support('post-thumbnails');  
}  

// Insertar dentro de index.php //

<?php the_post_thumbnail(); ?>


// name of the thumbnail, width, height, crop mode
add_image_size( 'post-image',  300, 180, true ); // post image shown in main blog feed
add_image_size( 'featured-image',  652, 245, true ); // large post thumbnail shown in the Featured section
add_image_size( 'slide-image',  900, 300, true ); // really large image for the main front-page slider
add_image_size( 'slide-image-small',  200, 200, true ); // small square image shown in carousel slider in footer
add_image_size( 'latest-post-widget',  80, 80, true ); // really small square shown for latest posts widget
add_image_size( 'related-posts',  180, 180, true );  

the_post_thumbnail('post-image'); // replace post-image with the name of your thumbnail, as declared above


if(has_post_thumbnail()) {
	the_post_thumbnail('featured-image');
} else {
        // show a default image if no thumbnail is set
	echo '<img src="path/to/yourimage/jpg" />';
}

以上是关于PHP Wordpress后缩略图的主要内容,如果未能解决你的问题,请参考以下文章

PHP 在Wordpress中激活后缩略图功能,但如果没有要显示的图像则不显示任何内容

使用timthumb.php截取文章缩略图

PHP wordpress缩略图

PHP 为Wordpress主题启用帖子缩略图

PHP Wordpress 2.9发布缩略图

PHP 简单的WordPress缩略图功能