我正在使用此代码,但它不是在第一次请求之后:
<?php $thePostIdArray = array( '2', '4', '5'); ?>
<?php $limit = 4; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $counter++; ?>
<?php if ( $counter < $limit+1): ?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php $post_id = $thePostIdArray[$counter-1]; ?>
<?php $queried_post = get_post($post_id); ?>
<?php $title =$queried_post->post_title; ?>
<?php $content = $queried_post->post_content; ?>
<h2><span><?php echo $title ?></span></h2>
<?php echo $content; ?> </div>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
即使查询了页脚和侧边栏,也只是放置请求的第一页(2)。我消除了侧边栏和页脚,但没有变化,所以问题不在于它们。 任何帮助将不胜感激。顺便说一句,我正在使用持续的wordpress
答案 0 :(得分:0)
您不需要The Loop,因为您知道帖子(或页面)的ID。
<?php
$thePostIdArray = array( '2', '4', '5');
foreach ($thePostIdArray as $thePostId):
$thePost = get_post($thePostId);
<?php if (!empty ($thePost)): ?>
<div class="post" id="post-<?php echo $thePostId; ?>">
<?php $title =$thePost->post_title; ?>
<?php $content = $thePost->post_content; ?>
<h2><span><?php echo title ?></span></h2>
<?php echo $content; ?> </div>
<?php endif;
endforeach; ?>