我的单曲。php我想显示当前帖子,在它下面我想列出cat-2中的所有帖子。在我的循环中,我试图用cat-2查询帖子,但它仍然显示当前帖子。
<?php global $query_string;
$posts = query_posts($query_string.\'\'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php endif; ?>
<?php the_content(); // Dynamic Content ?>
<?php edit_post_link(); ?>
<?php endwhile; ?>
<?php else: ?>
<h1><?php _e( \'Sorry, nothing to display.\', \'html5blank\' ); ?></h1>
<?php endif; ?>
<?php rewind_posts(); ?>
<hr>
<?php global $query_string; // required
$posts = query_posts($query_string.\'&cat=2,&order=ASC\'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>"><img title="<?php the_title(); ?>" alt="<?php the_title(); ?>" class="wp-post-image" src="<?php the_post_thumbnail_url(); ?> " style="width:100%; height:auto;"></a>
<h4><?php the_title(); ?></h4>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php wp_reset_query(); // reset the query ?>
最合适的回答,由SO网友:Rishabh 整理而成
类别的帖子列表可以使用wp_query 像这样
$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\' => \'post\', //Specifying post type
\'posts_per_page\' => 10, //How many posts per page
\'cat\' =>\'cat2\', //Specifying post category to show posts
\'paged\' => $paged //For pagingation (if required)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h3><?php the_title();?></h3>
<?php
endwhile; ?>