如何在 WordPress 的帖子中添加缩略图?
我想在首页的帖子中添加缩略图。但不知道该怎么做。我的主题不支持custom_field。该类别的代码之一是我粘贴在这里......
<div class="featured">
<h2>HEADLINES</h2>
<!--This is where the thumbnails are found for the homepage bottom section - note the custom field name for this image is "thumbnail". Recommended image size is 70x70, as the stylesheet is written for this size.-->
<?php $recent = new WP_Query("cat=3&showposts=3");
while($recent->have_posts()) : $recent->the_post();?>
<?php the_post_thumbnail(); ?>
<?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
<a href="<?php the_post_thumbnail() ?>" rel="bookmark"><imgstyle="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="alt text" /></a>
<?php else: ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><imgstyle="float:left;margin:0px 10px 0px 0px;" src="<?php bloginfo('template_url'); ?>/images/thumbnail.jp" alt="Default thumbnail" /></a>
<?php endif; ?>
<b><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></b>
<?php the_content_limit(80, ""); ?>
<div style="border-bottom:1px dotted #AFAFAF; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div>
<?php endwhile; ?>
我将扩展名 jpg 重命名为 jp 因为 stackoverflow 不允许我添加图像。我也改变了
I want to add thumbnails in the post in front page. But don't know how to do it. My theme do not support custom_field. one of the category's code is I pasted here.......
<div class="featured">
<h2>HEADLINES</h2>
<!--This is where the thumbnails are found for the homepage bottom section - note the custom field name for this image is "thumbnail". Recommended image size is 70x70, as the stylesheet is written for this size.-->
<?php $recent = new WP_Query("cat=3&showposts=3");
while($recent->have_posts()) : $recent->the_post();?>
<?php the_post_thumbnail(); ?>
<?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
<a href="<?php the_post_thumbnail() ?>" rel="bookmark"><imgstyle="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="alt text" /></a>
<?php else: ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><imgstyle="float:left;margin:0px 10px 0px 0px;" src="<?php bloginfo('template_url'); ?>/images/thumbnail.jp" alt="Default thumbnail" /></a>
<?php endif; ?>
<b><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></b>
<?php the_content_limit(80, ""); ?>
<div style="border-bottom:1px dotted #AFAFAF; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div>
<?php endwhile; ?>
I rename the extension jpg to jp coz stackoverflow donot allow me to add image. I also changed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 WordPress 2.9 之前,缩略图必须是自定义字段。从那时起,添加了本机支持。
在 Codex 上阅读相关内容:http://codex.wordpress.org/Post_Thumbnails
简而言之,将其添加到主题的函数中.php 文件:
然后,将其添加到您希望缩略图显示的主题中:
Prior to WordPress 2.9, thumbnails had to be custom fields. Since then, native support has been added.
Read about it on the Codex: http://codex.wordpress.org/Post_Thumbnails
In a nutshell, add this to your theme's functions.php file:
Then, add this to your theme where you want the thumbnail to appear:
你可以试试这个。
http://wordpress.org/extend/plugins/wp-post-thumbnail
不过我没有测试过。谢谢
You can try this one.
http://wordpress.org/extend/plugins/wp-post-thumbnail
I didn't test it though. Thanks