我想显示来自自定义分类法类别的帖子,但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()) : ?>
希望我的英语不会伤到你的眼睛。。。。