WordPress的:使用自定义字段来定义要显示在循环中的帖子

问题描述:

我想使用自定义字段,其中我输入我想显示的帖子的帖子ID号,用逗号分隔。但是,出于某种原因,仅显示一系列帖子ID的第一个帖子。有人可以帮忙吗? $ nlPostIds的值是(减去引号):“1542,1534,1546”。这里的代码...最重要的部分是第4行'post__in' => array($nlPostIds)WordPress的:使用自定义字段来定义要显示在循环中的帖子

<?php 
$nlPostIds = get_post_meta($post->ID, 'nlPostIds', true); 
$args=array(
    'post__in' => array($nlPostIds) 
    ); 
query_posts($args); 
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 

<div class="entry"> 
      <div class="post" id="post-<?php the_ID(); ?>"> 
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
<div class="allinfos"><span class="date"><?php the_time('F jS, Y') ?></span> | <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </span> | <span class="category">Posted in <?php the_category(', ') ?></span> <!-- by <?php the_author() ?> --></div> 

        <?php the_content('More &raquo;'); ?> 

<?php the_tags('Tags: ', ', ', ' '); ?> <?php edit_post_link('Edit', '[ ', ' ]'); ?> 
<div class="clear"></div> 
</div></div> 
<?php endwhile; endif; ?> 

谢谢!

我想你还需要在$args数组中传递参数'posts_per_page'作为-1(请参阅Codex on query_posts())。

UPDATE:

道歉,我只是重读你的问题,我想我知道这个问题。将$nlPostIds作为直接参数传递,而不将其放置在数组中。 每个元素是一个ID,你只能通过一个数组。在这个护理中,你只是传递一个逗号分隔的字符串。

更新:

使用;

$args = array('post__in' => @explode(',', $nlPostIds), 'posts_per_page' => -1); 
+0

感谢deadmedic,但似乎并没有做任何事情,不幸的是 – 2010-05-28 16:53:09

+0

检查我的修订的答案 - 应该做的伎俩:) – TheDeadMedic 2010-05-28 20:20:49

+0

对不起,我的意见可能是一个有点混乱 - 只是为了确认,你做; '$ args = array('post__in'=> $ nlPostIds)',not; '$ args = $ nlPostIds'? – TheDeadMedic 2010-05-28 22:29:21