
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.
Adding thumbnail support to a topic
In order for the “Thumbnail entry” block to appear in the article editing (under the category selection), the following text should be added in the function.php file of your active theme.
if (function_exists ('add_theme_support')) add_theme_support ('post-thumbnails');
To display thumbnails in your topic you need to insert:
the_post_thumbnail ();
the_post_thumbnail ()
')
To my great surprise, I did not find a description of this function in the code. She has two arguments:
- image size (either in pixels or in words);
- image attributes.
// ,
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 .
This is not a tricky way, you can scale the image on the fly, and the proportions are preserved. Typical dimensions in pixels are set in “Settings / Media Files”. It is also worth noting that none of the parameters is optional.
Personally, I did in my blog on the main page “Thumbnail” + quotation of the article, in the body of the article “Average size”.
// 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 .
Insert thumbnails in RSS
Obviously, the picture in the RSS feed increases the chances that the article will be read in full. Add the following code to the function.php file:
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 .
Well, now you will spend 5 minutes more on writing one article. How else? A picture for a miniature must be found, prepared, poured.
Original source.Enjoy your blogging!