两天以来,我一直在尝试解决自定义分类法(categories)的问题。我有一个名为“Portfolio”的自定义帖子类型,它按预期工作,但我注册的层次分类法存在问题。我给它起了个名字:“画廊”。它不显示自定义分类法,只显示我博客中的默认类别。我在这里发现了一些类似的问题,但我真的不知道如何在我的案例中采用其他人的解决方案。不幸的是,我对wordpress还是个新手。有人能帮我吗?
这是我循环中的代码。php是我自定义帖子类型的模板(这是我的主页):
<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\');
$galleries=get_categories($args);
foreach($galleries as $gallery){ ?>
<li><a href="#<?php echo $gallery->gallery_nicename; ?>" class="<?php echo $gallery->gallery_nicename; ?>"><?php echo $gallery->name; ?></a></li>
<?php } ?>
</ul>
<div class="clearfix"></div>
这是我函数中的代码。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 ));
提前感谢!