【问题标题】:How can I display only the thumbnail and title of a post in WordPress?如何在 WordPress 中仅显示帖子的缩略图和标题?
【发布时间】:2012-02-26 19:15:12
【问题描述】:

如何在 WordPress 中仅显示帖子的缩略图和标题,如下所示:http://themes.premiumpixels.com/?theme=artiste

附:我没有做任何广告,我只是发布了一个问题,因为我不知道如何做这样的事情。

【问题讨论】:

    标签: wordpress themes thumbnails title


    【解决方案1】:

    // 从你的循环中删除 the_content() 或 the_excerpt() 调用

    <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>    
                   <!-- do stuff ... -->
                   if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail  assigned to it.
                      the_post_thumbnail();
                   }
                    post_title();// to display the post title
                   <?php endwhile; ?>
    <?php endif; ?>
    

    【讨论】:

    • 别以为他问的是什么。
    • 他不是只想显示帖子缩略图和标题...如果我没记错的话,您提供的 sol 会显示帖子的文本摘录(我认为默认情况下为 40 个字符)
    • 我可能错了,但根据该链接,不仅有标题,还有一些额外的小信息
    • 我也认为他不知道 the_post_thumbnail().. 所以我很相信他也不知道在 function.php 中添加它,这就是我将他链接到 tuto 的原因
    • 我认为这些只是类别......但是你在functions.php中添加the_post_thumbnail()是对的......我忘了提
    【解决方案2】:

    您需要为图像执行此操作:

    http://www.wpbeginner.com/wp-themes/how-to-add-post-thumbnails-in-wordpress/

    你需要为小文本做这个:

    在function.php中添加这个:

      add_post_type_support( 'page', 'excerpt' );
    

    然后将其添加到模板中的 post_thumbnail 下方,因为链接会向您展示:

        <?php  the_exceprt(); ?>
    

    【讨论】:

      猜你喜欢
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2011-08-09
      相关资源
      最近更新 更多