2013-05-03 108 views
0

我有一個名爲'portcat'的自定義帖子類型,我想在我的頁面上顯示只有一個portcat類別('遊戲' - 其ID爲'3')的結果。下面的代碼顯示了所有的類別,我不確定我需要添加什麼來使其僅顯示「遊戲」類別?如何僅在自定義帖子類型中顯示一個類別?

<div class="greyblock"> 
     <h4 class="nomar"><?php echo the_title(); ?></h4> 
     <div class="sep"></div> 

      <?php echo $firstCat[0]->cat_name; ?> 

      <div class="clear"></div> 
      <ul class="blogpost_list columns3"> 

      <?php 
      $args = array(
      'post_type' => 'port', 
      'paged' => $paged, 
      'posts_per_page' => get_theme_option("portfolio_work_count"), 
      'cat_name' => 'games' 
      ); 
      $wp_query = new WP_Query($args); 

      ?> 
      <?php while ($wp_query->have_posts()) : $wp_query->the_post(); 
      #We have: 
      #get_permalink() - Full url to post; 
      #get_the_title() - Post title; 
      #get_the_content() - Post text; 
      #get_post_time('U', true) - unix timestamp 

      $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail'); 


      echo " 
      <li> 
        <center><img alt='".get_the_title()."' src='".TIMTHUMBURL."?w=120&h=250&src=".$featured_image[0]."'> 
        <h4>".get_the_title()."</h4></center>"; 
        $terms = get_the_terms($post->ID, 'portcat'); 
        if ($terms && ! is_wp_error($terms)) { 

        $draught_links = array(); 

        foreach ($terms as $term) { 
         $draught_links[] = $term->name; 
        } 

        $on_draught = join(", ", $draught_links); 
        } 

      echo " 
      <p>".get_the_excerpt()."</p> 
       <center><a href='".get_permalink()."' class='read'>Read More</a></center>      
       <br class='clear' /> 
      </li> 
      "; 

      endwhile; ?> 

     </ul> 
    </div> 
    <?php get_pagination() ?> 
    <?php $wp_query = null; $wp_query = $temp; ?> 
+0

什麼是'的var_dump($ wp_query)'的輸出? – AlexP 2013-05-03 00:15:47

回答

0

試着改變你的$args

$args = array(
    'post_type' => 'port', 
    'paged' => $paged, 
    'posts_per_page' => get_theme_option("portfolio_work_count"), 
    'category__in ' => 'games' 
    ); 
相關問題