All reviews of WP 2.9 say that the new version has the opportunity to use thumbnails. Some themes for earlier versions actively used this functionality. For example, Arthemia Free. Not so long ago, I redid the design of my blog to use thumbnails. I want to share my experience - to show how to add thumbnails to your theme using the existing functionality. By the way, it is also suitable for displaying in RSS.if (function_exists ('add_theme_support')) add_theme_support ('post-thumbnails');
the_post_thumbnail ();
// ,
the_post_thumbnail( 'thumbnail' , array( 'class' => 'alignleft' ));
// ,
the_post_thumbnail( 'medium' , array( 'class' => 'alignright' ));
// ,
the_post_thumbnail( 'large' , array( 'class' => 'aligncenter' ));
// 'my_own_class'
the_post_thumbnail(array(400,345), array( 'class' => 'alignright my_own_class' ));
* This source code was highlighted with Source Code Highlighter .// index.php
<div class = "thumbnail" >
<a href= "<?php the_permalink() ?>" ><?php the_post_thumbnail( 'thumbnail' ); ?></a>
</div>
<?php the_excerpt(); ?>
// single.php
<div class = "thumbnail" >
<?php the_post_thumbnail( 'medium' ); ?>
</div>
<?php the_content( '<p>Read the rest of this entry »</p>' ); ?>
* This source code was highlighted with Source Code Highlighter .function insertThumbnailRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$add_thumbnail = "
<div style=" float : left; padding: 0 10px 5px 0; ">" .get_the_post_thumbnail( $post->ID, 'thumbnail' ). "</div>
" ;
$content = $add_thumbnail . $content;
}
return $content;
add_filter( 'the_excerpt_rss' , 'insertThumbnailRSS' );
add_filter( 'the_content_feed' , 'insertThumbnailRSS' );
}
* This source code was highlighted with Source Code Highlighter .Source: https://habr.com/ru/post/80083/
All Articles