2011-04-02 83 views
2

我创建一个记录标签的wordpress主题。一个方面是视频画廊。WordPress的:循环虽然自定义帖子类型,只返回给定的分类结果

我使用名为'videos'的自定义帖子类型创建了该图库。下面的代码是我放在我的functions.php文件来设置职位类型:

add_action('init', 'create_my_post_types'); 
     function create_my_post_types() { 

register_post_type('videos', 
     array(
      'labels' => array(
       'name' => __('Videos'), 
       'singular_name' => __('Video'), 
       'add_new' => 'Add New Video', 
       'edit' => 'Edit Video' 
      ), 
      'public' => true, 
      'exclude_from_search' => false, 
      'supports' => array('title', 'editor', 'thumbnail','page-attributes','excerpt'), 
      'rewrite' => array('slug' => 'videos', 'with_front' => false), 

     )); 
    } 

我还创建了一个名为“艺术家”这样我就可以在艺术家姓名分配给每个视频我上传自定义分类。

add_action('init', 'create_videos_taxonomies'); 

    function create_videos_taxonomies() { 

     register_taxonomy(
      'artist', 
      'videos', 
      array( 
        'hierarchical' => false, 
        'label' => 'Artist', 
        'query_var' => true, 
        'show_tagcloud' => true, 
        'show_ui' => true, 
        'rewrite'=>array('slug' => 'artists', 'with_front' => false) 
       ) 
      ); 
     } 

此时,在后端一切正常,视频页面成功返回所有视频。

在我的网站的另一个区域,我为每一位艺术家设置了页面。在这些艺术家页面的任何一个上,我希望能够遍历我创建的自定义帖子类型中的所有视频,并且只返回给定分类中的结果。下面是我的代码遍历一个自定义后类型:

<?php $loop = new WP_Query(array('post_type' => 'videos', 'post_child' => 0, 'posts_per_page' => 5)); ?> 
    <?php while ($loop->have_posts()) : $loop->the_post(); ?> 
<?php the_post_thumbnail('video'); ?> 
<?php the_content(); ?> 
<?php endwhile; ?> 

这成功地遍历视频,并返回5最近。我需要使用特定的分类标准段或ID来循环播放所有视频。例如,我创建了一个名为“粉碎宫殿”的分类学,它有一个“粉碎宫殿”和一个“17”的ID。任何想法如何循环这个自定义帖子类型,只返回给定的分类结果?

+0

任何这运气? – 2011-04-02 04:57:12

+0

是的,答案在这里给出:http://wordpress.stackexchange.com/questions/13753/looping-though-custom-post-types-and-only-return-results-in-a-given-taxonomy – JCHASE11 2011-04-02 05:31:01

回答

0
'category_name' => 'Category Slug Here' 
相关问题