禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

wordpress 获取指定文章ID组的文章列表

禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

有时候,我们需要显示指定文章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();
}
?>

方法二:(如果需要分页)

<?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();
?>

0 个评论

 
联系
目前暂停一切业务,客服消息可能不会及时回复,谢谢理解。
在线咨询
    在线咨询
    禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。