我正在尝试获取第一个循环中帖子的ID(使用<?php $postid = get_the_ID(); ?>
) 并在变量中使用它($postid
) 要从第二个循环中排除该帖子(使用post__not_in
):
<?php
/**
* Replies Loop
*
* @package bbPress
* @subpackage Theme
*/
?>
<?php if ( ! get_query_var( \'paged\' ) ) : ?>
<?php
$args = array(
\'post_type\' => \'bbp_reply\',
\'posts_per_page\' => \'1\',
\'paged\' => \'2\',
\'post_parent\' => $post->ID,
\'gdsr_sort\' => \'thumbs\',
\'gdsr_ftvmin\' => \'1\',
\'gdsr_order\' => \'desc\'
);
?>
<?php query_posts( $args ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="most-voted">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php bbp_reply_admin_links(); ?>
</div>
<?php $postid = get_the_ID(); // capture the id ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<p>________________</p>
<?php endif; ?>
<?php
$default = array(
\'post__not_in\' => $postid
);
?>
<?php if ( bbp_has_replies( $default ) ) : ?>
<?php get_template_part( \'pagination\', \'bbp_replies\' ); ?>
<?php while ( bbp_replies() ) : bbp_the_reply(); ?>
<div class="topic-entry">
<div class="topic-author">
<?php bbp_reply_author_link( array( \'type\' => \'avatar\' ) ); ?>
<?php bbp_reply_author_link( array( \'type\' => \'name\' ) ); ?>
<?php printf( __( \'%1$s\', \'bbpress\' ), get_the_date() ); ?>
</div>
<div class="topic-content">
<?php bbp_reply_content(); ?>
<span class="like-counter"><?php DisplayVotes(get_the_ID()); ?></span>
</div>
<?php wp_gdsr_render_article_thumbs(); ?>
<?php bbp_reply_admin_links(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
但出于某种原因,我得到了这个错误:
Warning: array_map(): Argument #2 should be an array in /home/alex/www/taiwantalk/wp-includes/query.php on line 2104 Warning: implode(): Invalid arguments passed in /home/alex/www/taiwantalk/wp-includes/query.php on line 2104
最合适的回答,由SO网友:Bainternet 整理而成
post__not_in
接受数组以便更改
<?php $postid = get_the_ID(); // capture the id ?>
至
<?php $postid[] = get_the_ID(); // capture the id ?>
你会没事的。