wordpress精选帖子

时间:2010-08-29 00:57:05

标签: wordpress metadata custom-fields

我正在尝试使用wordpress创建一个投资组合网站,

每个帖子都有查看costum字段,其中一个名为type - 值为“featured”或“not-featured”

现在当用户点击帖子标题时 - 他们会去single.php查看整个帖子,在这里我希望显示所有精选缩略图

我试过这个

         <?php while ( have_posts() ) : the_post() ?>

      <?php  if(get_post_meta($post->ID, 'type', true) == "featured") {; ?>
  <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"> 
<img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a></h2>
<?php  }; ?>
<div class="entry-content">

     </div><!– .entry-content –> 
      <?php endwhile; ?> 

(这个代码与我在INDEX.PHP上使用的代码类似,但它在那里工作,在这里单独使用。它不工作)

但是这不会显示所有缩略图(只有当前帖子的缩略图(这是特色文章))

这是我尝试从空白创建主题的第一次尝试,所以我不确定错误是什么

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

在单个帖子视图为一个帖子的情况下,您的问题中的代码仅循环查看为当前视图查询返回的帖子。您想要执行新查询以检索具有所需元值的所有帖子:

<?php
  query_posts(array("meta_key" => "type", "meta_value" => "featured"));
  if (have_posts()) : while (have_posts()) : the_post();
?>
  <!-- Display thumbnails -->
<?php endwhile; endif; ?>