自定义分类的类别不显示任何帖子

时间:2011-07-25 作者:Adrian

我想显示来自自定义分类法类别的帖子,但realy不知道如何实现这一点。我正在使用同位素过滤,这与默认的帖子类别一样有效。我可以单击某个特定类别,它会显示与该类别相关的所有帖子,但它不适用于我的自定义分类法。我可以看到所有子分类法(感谢Rajeev Vyas),但当我单击其中一个时,不会显示任何帖子。你能告诉我我做错了什么吗?

这是我函数中的代码。php:

add_action(\'init\', \'portfolio_register\');
function portfolio_register() {
     $labels = array(
        \'name\' => _x(\'My Portfolio\', \'post type general name\'),
        \'singular_name\' => _x(\'Portfolio Item\', \'post type singular name\'),
        \'add_new\' => _x(\'Add New\', \'portfolio item\'),
        \'add_new_item\' => __(\'Add New Portfolio Item\'),
        \'edit_item\' => __(\'Edit Portfolio Item\'),
        \'new_item\' => __(\'New Portfolio Item\'),
        \'view_item\' => __(\'View Portfolio Item\'),
        \'search_items\' => __(\'Search Portfolio\'),
        \'not_found\' =>  __(\'Nothing found\'),
        \'not_found_in_trash\' => __(\'Nothing found in Trash\'),
        \'parent_item_colon\' => \'\'
    );
    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'menu_icon\' => get_stylesheet_directory_uri() . \'/images/portfolio-icon.png\',
        \'rewrite\' => true,
        \'capability_type\' => \'post\',
        \'hierarchical\' => false,
        \'menu_position\' => null,
        \'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'comments\')
      ); 
    register_post_type( \'portfolio\' , $args );
    flush_rewrite_rules();
}
// Custom taxonomy for Portfolio Categories (Galleries)
register_taxonomy(\'galleries\', array(\'portfolio\'), array(\'hierarchical\' => true, \'label\' => \'Galleries\', \'singular_label\' => \'Gallery\', \'rewrite\' => true, \'public\' => true ));
这段代码来自我的循环。php是我的自定义帖子类型模板:

 <?php /* Display filter options if homepage  */ ?>
<?php if(is_home()) { ?>
<div id="filtering-nav">
        <a href="#" class="filter-btn"><span>Filter</span></a>
        <ul>
                <li><a href="#all" class="all">All</a></li>
            <?php
            $args=array( \'orderby\' => \'name\', \'taxonomy\'=>\'galleries\' );
            $categories=get_categories($args);
            foreach($categories as $category) {  ?>
                    <li><a href="#<?php echo $category->category_nicename; ?>" class="<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a></li>
            <?php } ?>
        </ul>
        <div class="clearfix"></div>
</div>
<?php } ?>

<?php /* If this is the homepage, display all posts on one page  */ 
if(is_home() && get_option(\'show_all\') && !is_search()) { query_posts(\'post_type=portfolio\', \'posts_per_page=-1\'); } ?>

<?php if (have_posts()) : ?>
希望我的英语不会伤到你的眼睛。。。。

1 个回复
SO网友:Bainternet

您需要修改分类术语页面上的查询以获取您的文章类型

尝试:

add_filter(\'pre_get_posts\', \'filter_custom_taxonomy_posts\');
function filter_custom_taxonomy_posts($query) {
    if (is_tax(\'Your_Taxonomy_Name\')) {
        $query->set(\'post_type\', \'portfolio\');
        $query->set(\'posts_per_page\', -1);
    }
  return $query;
}

结束

相关推荐

Taxonomy filter all children

我有一个自定义分类过滤器,它将过滤选定分类中的所有页面。我希望代码能够选择该分类法中的页面,以及千页的子页面。这是密码。add_action(\'restrict_manage_posts\', \'restrict_manage_posts_section\'); function restrict_manage_posts_section() { global $post_type; if ( is_object_in_taxonomy( $post_t