2012-07-18 60 views
1

帖子我有一点奇怪的问题,与我的WP-查询。我有一个自定义帖子类型(投资组合),用一种名为year的自定义分类法。我每年都有类别,所以我想要做的是显示每年的所有帖子。问题是,只有2012年的作品。如果我订购类别ASC/DESC - 只有2012年的作品无所谓。WordPress的 - 获取自定义分类类别

<section id="content"> 
    <?php 
    $categories = get_categories('taxonomy=year&order=DESC'); 
    foreach($categories as $category) : ?> 
    <article class="year"> 
     <h2><?php echo $category->name ?></h2> 
     <div class="items"> 
     <?php 
     $posts = get_posts('taxonomy=year&post_type=portfolio&year=' . $category->slug); 
     foreach($posts as $post) : ?> 
      <div class="item"> 
      <?php 
      $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); 
      echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox[' . $category->slug . ']" >'; 
      the_post_thumbnail('thumbnail'); 
      echo '</a>'; 
      ?> 
      </div> 
     <?php endforeach; ?>      
     </div> 
    </article> 
    <?php 
    endforeach; 
    wp_reset_query(); 
    ?> 
</section> 

我在做什么错?对我来说,这似乎是正确的。我已经尝试了一堆不同的需要这一点,一切从实际querys荒谬的分类法,但我只是无法得到它的权利..

预先感谢您!

+0

使用自定义后类型名称获得类别列表:http://wp.me/p4esuX-3k – 2014-12-31 06:50:32

回答

0

我已经解决了它自己,现在,仍然没有得到它100%,但它的作品至少..有一定是这样的一些更聪明的办法,因为即时通讯现在循环槽全部图像进行每学期。那么,这里是代码(按照来自定制分类的术语来分组帖子)。

<section id="content"> 
<?php 
$categories = get_categories('taxonomy=year&order=DESC'); 

foreach($categories as $category) { ?> 

    <article class="year"> 
     <h2><?php echo $category->name ?></h2> 
     <div class="items"> 
     <?php 
     $args = array(
      'post_type' => 'portfolio' 
     ); 

     query_posts($args); 
     $count = 0; 

     while(have_posts()) : the_post(); 
      $terms = get_the_terms($post->ID, 'year'); 

      foreach ($terms as $term) { 
       $imgslug = $term->name; 
      } 

      if($imgslug == $category->name) { 
       if($count == 6) { 
        echo '<div class="expanded-items">'; 
       } 
     ?> 
       <div class="item"> 
       <?php 
       $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); 
       echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox[' . $category->slug . ']" >'; 
       the_post_thumbnail('thumbnail'); 
       echo '</a>'; 
       ?> 
       </div> 

       <?php 
      } 
      $count++; 

     endwhile; 
     if($count >= 6) { 
      echo '</div>'; 
     } 
     ?>     
     </div> 
     <div class="expand">Visa fler</div> 
    </article> 
<?php } ?> 
</section> 

这是一个可扩展列表,所以它从头开始显示6,然后展开显示其余项目(jQuery)。

相关问题