有时候,我们需要显示指定文章ID数组的文章列表,那么看看下面代码,可能会帮助到你:
方法一:
1 |
<?php $ids = array(548,555,587,583,585); $my_query = query_posts(array('post__in' => $ids,'post_type'=> 'parks')); global $post; foreach ($my_query as $post) { $posts_by_id[$post->ID] = $post; } foreach ($ids as $id) { if (!$post = $posts_by_id[$id]) continue; setup_postdata($post); echo '<p>TITLE: ';the_title();echo ' - ';the_ID(); '</p>'; the_content(); } ?> |
方法二:(如果需要分页)
1 |
<?php global $wp_query; $args = array_merge( $wp_query->query_vars, array('post__in' => $ids, 'paged' => $paged) ); query_posts( $args ); while ( have_posts() ) : the_post(); //代码 endwhile;wp_reset_query(); ?> |
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。