Wordpress循环不仅显示帖子
我有以下代码:Wordpress循环不仅显示帖子,wordpress,loops,post,while-loop,posts,Wordpress,Loops,Post,While Loop,Posts,我有以下代码: <div id="container" class="activiteiten_singleview"> <div id="content_activiteiten"> <h1 id="pagetitle"><?php echo get_the_title($ID);?></h1> <?php if (have_posts()) : ?&
<div id="container" class="activiteiten_singleview">
<div id="content_activiteiten">
<h1 id="pagetitle"><?php echo get_the_title($ID);?></h1>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();
if ( is_page('48') ) {
query_posts( 'cat=4' );
}
if ( is_page('44') ) {
query_posts( 'cat=6' );
}
if ( is_page('46') ) {
query_posts( 'cat=9' );
}
if ( is_page('50') ) {
query_posts( 'cat=8' );
}
if ( is_page('52') ) {
query_posts( 'cat=7' );
}?>
<div class="postwrapper">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
</div>
<?php endwhile; endif;?>
</div>
</div><!-- #container -->
问题在于,不仅在postwrapper div中创建了帖子,而且还创建了带有空摘录的页面标题。我只想将所有帖子显示为postwrapper 试试这个:
<?php
if ( is_page('48') ) {
query_posts( 'cat=4' );
}
if ( is_page('44') ) {
query_posts( 'cat=6' );
}
if ( is_page('46') ) {
query_posts( 'cat=9' );
}
if ( is_page('50') ) {
query_posts( 'cat=8' );
}
if ( is_page('52') ) {
query_posts( 'cat=7' );
}
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="postwrapper">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
如果您在页面模板中使用它,请尝试添加查询帖子
<div id="container" class="activiteiten_singleview">
<div id="content_activiteiten">
<h1 id="pagetitle"><?php echo get_the_title($ID);?></h1>
<?php query_posts('post_type=post'); if (have_posts()) : ?>
<?php while (have_posts()) : the_post();
if ( is_page('48') ) {
query_posts( 'cat=4' );
}
if ( is_page('44') ) {
query_posts( 'cat=6' );
}
if ( is_page('46') ) {
query_posts( 'cat=9' );
}
if ( is_page('50') ) {
query_posts( 'cat=8' );
}
if ( is_page('52') ) {
query_posts( 'cat=7' );
}?>
<div class="postwrapper">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt(); ?></p>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
</div>
</div><!-- #container -->
尝试回显_摘录();这不会改变什么。带有页面标题但没有内容的postwrapper仍然存在。也许我不清楚你想要实现什么。您想在一个postwrapper中显示所有查询的帖子吗?我想在另一个postwrapper中显示所有查询的帖子,这样就行了。但是循环创建的第一个postwrapper不是文章的内容,而是h3中的pagetitle,p为空。因此我希望只创建文章。从代码中删除
。