Wordpress“特色”帖子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress“特色”帖子相关的知识,希望对你有一定的参考价值。

This can be dropped into either index.php or any custom page template to display posts in the "Featured" category.

Alternatively you could create a custom loop (loop-featured.php, for example) using this query.
  1. <div id="featured-posts">
  2. <?php
  3. $featured_query = "
  4. SELECT wposts.*
  5. FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
  6. WHERE wposts.ID = wpostmeta.post_id
  7. AND wpostmeta.meta_key = 'featured'
  8. AND wpostmeta.meta_value = 'yes'
  9. AND wposts.post_type = 'post'
  10. ";
  11. $featured = $wpdb->get_results($featured_query, OBJECT);
  12. ?>
  13.  
  14. <?php if ($featured): ?>
  15. <?php foreach ($featured as $post): ?>
  16. <?php //print_r($post); ?>
  17. <div class="post" id="post-<?php echo $post->ID ?>">
  18. <a href="<?php the_permalink() ?>">
  19. <div class="thumbnail">
  20. <?php echo get_the_post_thumbnail($post->ID, 'header-thumbnail'); ?>
  21. <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
  22. </div>
  23. </a>
  24.  
  25. <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
  26.  
  27. <div class="entry">
  28. <?php echo $post->post_excerpt; ?>
  29. </div>
  30.  
  31. <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
  32. <?php comments_popup_link('No Comments &raquo;', '1 Comment &raquo;', '% Comments &raquo;'); ?></p>
  33. </div>
  34. <?php endforeach; ?>
  35.  
  36. <?php else : ?>
  37. <h2 class="center">Not Found</h2>
  38. <p class="center">Sorry, but you are looking for something that isn't here.</p>
  39. <?php include (TEMPLATEPATH . "/searchform.php"); ?>
  40. <?php endif; ?>
  41.  
  42. </div>

以上是关于Wordpress“特色”帖子的主要内容,如果未能解决你的问题,请参考以下文章

WordPress 自定义帖子特色图片、标题和内容社交媒体共享

不同的 Wordpress 特色图像叠加效果

悬停在帖子链接(WordPress)上时如何显示帖子的特色图片?

在静态 html 页面上显示最新的 wordpress 特色图片

通过 SQL 检索带有特色图片的 wordpress 帖子

Wordpress - 自定义帖子存档页面上的特色图片