2013-10-16 154 views
0

我有下面的代碼:WordPress的循環不僅顯示帖子

<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。

+0

嘗試回聲the_excerpt(); –

回答

1

試試這個:

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

這沒有改變。帶有頁面標題和無內容的postwrapper仍然存在。 –

+0

也許我不清楚你想達到什麼目的。你想要顯示所有查詢的帖子在** one ** postwrapper中嗎? – Peter

+0

我想在不同的postwrapper中顯示所有查詢的帖子,這是有效的。但循環創建第一個後置處理程序,而不是來自帖子的內容,但是在h3中使用頁面標題並且p是空的。 –

0

如果您使用的是它的網頁模板中嘗試加入query_posts

<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 -->