从显示中排除投资组合类别

时间:2013-09-12 08:10:58

标签: php wordpress categories portfolio

我想要求投资组合页面模板将一个投资组合类别排除在投资组合中。所以当它显示类别时:全部|旅游|宏|存档等我需要从顶部过滤器和全部Feed中排除存档(slug存档),因为我想将它放在名为Archive的单独页面上。

我该怎么做?

<?php
/*
Template Name: Portfolio number 1
*/
?>
<?php get_header(); ?>

<div class="container">

        <div id="homecontent">

            <ul id="portfolio-filter" class="filter clearfix">
                      <li class="active"><a href="javascript:void(0)" class="all">All</a></li>

                      <?php
                          // Get the taxonomy
                          $terms = get_terms('categories');
                                  $term_list = '';

                          // set a count to the amount of categories in our taxonomy
                          $count = count($terms); 

                          // set a count value to 0
                          $i=0;

                          // test if the count has any categories
                          if ($count > 0) {

                              // break each of the categories into individual elements
                              foreach ($terms as $term) {

                                  // increase the count by 1
                                  $i++;

                                  // rewrite the output for each category
                                  $term_list .= '<li><a href="javascript:void(0)" class="'. $term->slug .'">' . $term->name . '</a></li>';

                                  // if count is equal to i then output blank
                                  if ($count != $i)
                                  {
                                      $term_list .= '';
                                  }
                                  else 
                                  {
                                      $term_list .= '';
                                  }
                              }

                              // print out each of the categories in our new format
                              echo $term_list;
                          }
                      ?>
                  </ul>

                  <div style="clear: both;"></div>




                  <ul id="portfolio-list" class="filterable-grid clearfix centerrow filter-posts">

                        <?php 
                          // Set the page to be pagination
                          $paged = get_query_var('paged') ? get_query_var('paged') : 1;

                          // Query Out Database
                          $wpbp = new WP_Query(array( 'post_type' => 'myportfoliotype', 'posts_per_page' =>'99', 'paged' => $paged ) ); 
                        ?>

                        <?php
                          // Begin The Loop
                          if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post(); 
                        ?>

                        <?php 
                          // Get The Taxonomy 'Filter' Categories "categories"
                          $terms = get_the_terms( get_the_ID(), 'categories' ); 
                        ?>

                        <?php 
                        $large_image =  wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' ); 
                        $large_image = $large_image[0]; 
                        $another_image_1 = get_post_meta($post->ID, 'themnific_image_1_url', true);
                        $video_input = get_post_meta($post->ID, 'themnific_video_url', true);
                        $price = get_post_meta($post->ID, 'themnific_item_price', true);
                        $ribbon = get_post_meta($post->ID, 'themnific_class', true);
                        ?>

                        <li class="centerfourcol filter" data-id="id-<?php echo $count; ?>" data-type="<?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->slug)). ' '; } ?>">

                            <?php get_template_part('/includes/folio-types/home_carousel'); ?>

                        </li>


                      <?php $count++; // Increase the count by 1 ?>     
                      <?php endwhile; endif; // END the Wordpress Loop ?>
                      <?php wp_reset_query(); // Reset the Query Loop?>

                  </ul>
                  <?php
                      /* 
                       * Download WP_PageNavi Plugin at: http://wordpress.org/extend/plugins/wp-pagenavi/
                       * Page Navigation Will Appear If Plugin Installed or Fall Back To Default Pagination
                      */        
                      if(function_exists('wp_pagenavi'))
                      {              
                          wp_pagenavi(array( 'query' => $wpbp ) );
                          wp_reset_postdata();  // avoid errors further down the page
                      }
                  ?>
                  <div style="clear: both;"></div>

        </div><!-- #homecontent -->

</div>

<?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

我找到了答案,下面的代码只允许在投资组合中显示一个类别。

‘tax_query’ => array( array( ‘taxonomy’ => ‘categories’, ‘field’ => ‘slug’, ‘terms’ => ‘archive’, ‘operator’ => ‘IN’) ),