如何在 WordPress 的帖子中添加缩略图?

发布于 2025-01-01 08:55:08 字数 1636 浏览 3 评论 0原文

我想在首页的帖子中添加缩略图。但不知道该怎么做。我的主题不支持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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯下孤影 2025-01-08 08:55:08

在 WordPress 2.9 之前,缩略图必须是自定义字段。从那时起,添加了本机支持。

在 Codex 上阅读相关内容:http://codex.wordpress.org/Post_Thumbnails

简而言之,将其添加到主题的函数中.php 文件:

if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' ); 
}

然后,将其添加到您希望缩略图显示的主题中:

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
} 
?>

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:

if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' ); 
}

Then, add this to your theme where you want the thumbnail to appear:

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
} 
?>
相思故 2025-01-08 08:55:08

你可以试试这个。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文