2014-02-26 147 views
0

顯示我創建theme.I已動態添加的所有類別進入前menu.Now我希望所有的類別下的職位的WordPress的,當我在任何菜單上單擊item.But代碼獲取所有類別的所有帖子。這裏是我的代碼。特定類別的所有WordPress的帖子將在page.php文件

<?php 
       global $wp_query; 
       $id = $wp_query->post->ID; 
       $the_query = new WP_Query($id); 
       $count = 0; 
       // The Loop 
       if ($the_query->have_posts()) { 
       while ($the_query->have_posts()) { 
       $the_query->the_post();?> 
       <div class="page-header"><h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3></div> 
       <?php 
       $count++; 
       } 
       } else {?> 
       no posts found 
       <?php } 
       /* Restore original Post Data */ 
       wp_reset_postdata(); 
       ?> 

我該如何解決這個問題。

+0

如果你回聲出的$ id是什麼打印出來? – Howli

+0

然後被印刷類別ID ok.I已經測試它。但是,當我想要打印該類別下的所有的職位,則所有類別的所有的職位prints.how我可以解決這個問題。 –

回答

0

試試這個

<?php 
      global $wp_query; 
      $id = $wp_query->post->ID; 
      $the_query = new WP_Query($id); 
      $count = 0; 
      // The Loop 
    query_posts('cat=22'); #enter your category id here 
      if ($the_query->have_posts()) { 
      while ($the_query->have_posts()) : the_post(); 
      $the_query->the_post();?> 
      <div class="page-header"><h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>  
      </div> 
      <?php 
      $count++; 
    endwhile; 
      } 
    else 
    { 
    ?> 
      no posts found 
      <?php 
    } 
      /* Restore original Post Data */ 
      wp_reset_postdata(); 
      ?> 
0
$the_query = new WP_Query('cat='.$id); 
+0

我已經嘗試過了,但現在當我點擊的所有類別都出現了「現在行裏找到」菜單中的一個。 –

+0

點擊後必須包含一個類別..你檢查它? –

+0

你能給我你這有一個問題在線網站的鏈接? –

相關問題