我正在尝试在页面模板上显示自定义帖子类型的列表。当我查看页面时,我看到的不是不同的帖子,而是重复的实际页面。例如,如果我有 5 个帖子,实际页面(页眉内容页脚)将显示五次。看起来查询正在工作......以某种方式但我不确定出了什么问题。这是模板代码:
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('page'); ?>>
<h1><?php the_title(); ?></h1>
<article>
<div class="post-content page-content">
<?php the_content(); ?>
<?php wp_link_pages('before=<div class="pagination">&after=</div>'); ?>
</div><!--.post-content .page-content -->
</article>
</div><!--#post-# .post-->
<?php endwhile; ?>
<!-- Start search result code -->
<?php
//query_posts('post_type=listing&orderby=title&order=ASC&posts_per_page=9999');
?>
<?php
$querystr = "
SELECT *
FROM $wpdb->posts, $wpdb->postsmeta
WHERE wp_posts.ID = wp_postmeta.post_id
AND wp_postmeta.meta_key = 'listing_open'
AND wp_postmeta.meta_value = 'YES'
AND wp_posts.post_status = 'publish'
AND wp_posts.post_type = 'listing'
ORDER BY post_title
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts):
foreach ($pageposts as $postdata):
setup_postdata($postdata);
?>
<?php //if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include_once(get_bloginfo('template_url')."/layout-listings.php?id=".$postdata->ID); ?>
<?php //endwhile; endif; rewind_posts(); wp_reset_query(); ?>
<?php
endforeach;
endif;
?>
<?php
$querystr = "
SELECT *
FROM $wpdb->posts, $wpdb->postmeta
WHERE wp_posts.ID = wp_postmeta.post_id
AND wp_postmeta.meta_key = 'listing_open'
AND wp_postmeta.meta_value = 'NO'
AND wp_posts.post_status = 'publish'
AND wp_posts.post_type = 'listing'
ORDER BY post_title
";
$pageposts2 = $wpdb->get_results($querystr, OBJECT);
if ($pageposts2):
foreach ($pageposts2 as $postdata2):
setup_postdata($postdata2);
?>
<?php //if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include_once(get_bloginfo('template_url')."/layout-listings.php?id=".$postdata2->ID); ?>
<?php //endwhile; endif; rewind_posts(); wp_reset_query(); ?>
<?php
endforeach;
endif;
?>
<!-- End search result code -->