开发者

wordpress image showing up multiple times

I am writing a wordpress theme, and have run into a fairly basic problem. By default, when you inset an image into the post, it displays that image at the size you specify, on both the homepage and the single post.

I would like to have different sized images, displaying a thumbnail on the homepage, and a full sized image when you click through to the post. I am using wordpress 2.9's new thumbnail feature, which has created great thumbnails for the homepage. But now, I am stuck with a nice thumbnail next to a large photo (on the index/home page). On the single page, it is开发者_高级运维 displaying correctly with just the large picture.

Basically, I need to know how to tell wordpress to only display the large post image on the single page, not on the index.

Also: I have used the timthumb script, but I think the answer is far more basic then needing plugins or scripts

Thanks!


What is most likely happening is that you need to define an excerpt for that post to display on the home page so that the post_content isn't used along with the post_thumbnail. The drawback to this is that your full post won't display on the front page (or any other list page like category and search pages).


This can be completely, 100% achieved using 2.9's thumbnail feature in combination with timthumb. To do so, follow these directions:

in the functions.php file insert:

add_theme_support( 'post-thumbnails' );

In your index.php file, insert:

<?php the_post_thumbnail(array( 125,125 )); ?>

And finally, in your single.php, insert:

<?php
    $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
    if (has_post_thumbnail()) {
        echo '<div class="post-tnail"><a href="'.get_permalink().'" title="'.get_the_title().'"><img src="'.get_bloginfo('template_url').'/scripts/timthumb.php?src='.$thumbnail[0].'&amp;w=440&amp;zc=1&amp;q=95" alt="'.get_the_title().'" /></a></div>';
    }
?>

Basically, the functions.php add allows you to see the thumbanil feature on the back-end. Add a new thumbnail and it will display in the box. The homepage will automatically render the 125 x 125 thumbnail, and the single page will automatically render a proportional image with a fixed width of 440px. Took me forever to figure out, but this works!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜