2015-10-14 72 views
0

我在我的網站的不同部分使用此代碼,我想根據他們的類別在首頁的每個部分顯示不同的職位。 有人可以幫助他們添加一個類別那裏是「衝浪」,我已經嘗試了一切。有人可以幫我添加一個類別到這個文章嗎?

或者也許有不同的方式來做到這一點?

謝謝。

<div class="posts"> 

     <?php 
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
     $total_post_count = wp_count_posts(); 
     $published_post_count = $total_post_count->publish; 
     $total_pages = ceil($published_post_count/$posts_per_page); 

     if ("1" < $paged) : ?> 

      <div class="page-title section small-padding"> 

       <h4 class="section-inner"><?php printf(__('Page %s of %s', 'radcliffe'), $paged, $wp_query->max_num_pages); ?></h4> 

      </div> 

      <div class="clear"></div> 

     <?php endif; ?> 

      <?php while (have_posts()) : the_post(); ?> 

       <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

        <?php get_template_part('content', get_post_format()); ?> 


       </div> <!-- /post --> 

      <?php endwhile; ?> 

     <?php if ($wp_query->max_num_pages > 1) : ?> 

      <div class="archive-nav"> 

       <?php echo get_next_posts_link('&laquo; ' . __('Posts Antigos', 'radcliffe')); ?> 

       <?php echo get_previous_posts_link(__('Posts Recentes', 'radcliffe') . ' &raquo;'); ?> 

       <div class="clear"></div> 

      </div> <!-- /post-nav archive-nav --> 

     <?php endif; ?> 

    <?php endif; ?> 

</div>  </div> <!-- /posts --> 

回答

1

如果你試圖通過ID顯示類別,然後

  global $post; 
      $args = array('category' => '12'); 
      $cat_post= get_posts($args); 
      foreach($cat_post as $post) : setup_postdata($post); ?> 
       <li class="testimonial"><?php the_content(); ?></li><br/> 
      <?php endforeach; ?> 

注:在$args = array('category' => '12'); 是 的ID類別

卜■如果你想通過Name顯示類別,然後

  global $post; 
      $args = array('category_name' => 'uncatogerized'); 
      $cat_post= get_posts($args); 
      foreach($cat_post as $post) : setup_postdata($post); ?> 
       <li class="testimonial"><?php the_content(); ?></li><br/> 
      <?php endforeach; ?> 

這裏,uncategorized是一個類別名稱

+0

謝謝你,它的工作! – user3547049

相關問題