有时,我们需要显示具有指定文章 ID 数组的文章列表,所以看看下面的代码,它可能会对您有所帮助:
方法一:
<?php
Products
GG网络技术分享 2025-03-18 16:14 0
有时,我们需要显示具有指定文章 ID 数组的文章列表,所以看看下面的代码,它可能会对您有所帮助: 方法一:<?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();
}
?>
方法二:(如果需要分页)
<?phpglobal $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();
?>
Demand feedback