2014-02-26 104 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

你能给我你这有一个问题在线网站的链接? –

相关问题