摘要:此功能文章类目纵向管理,在wordpress主题的使用中单线的文章分类可能不足以组织目前的文章类别,所以我们需要再添加一…
此功能文章类目纵向管理,在wordpress主题的使用中单线的文章分类可能不足以组织目前的文章类别,所以我们需要再添加一组新的分类功能,那下面的代码就可以轻松实现那说到底这个功能的使用场景是怎样的呢,通常情况下,这个功能只出现在专题中,也就是说,这个功能的延伸是专题开发。大家可以综合利用一下。
把以下代码复制到functions.php文本始就可以生效为一个topics的分类选项组,而且自动调用的文章列表及菜单中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
//hook into the init action and call create_book_taxonomies when it fires
add_action( ‘init’, ‘create_topics_hierarchical_taxonomy’, 0 );
//create a custom taxonomy name it topics for your posts
function create_topics_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
‘name’ => _x( ‘Topics’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Topic’, ‘taxonomy singular name’ ),
‘search_items’ => __( ‘Search Topics’ ),
‘all_items’ => __( ‘All Topics’ ),
‘parent_item’ => __( ‘Parent Topic’ ),
‘parent_item_colon’ => __( ‘Parent Topic:’ ),
‘edit_item’ => __( ‘Edit Topic’ ),
‘update_item’ => __( ‘Update Topic’ ),
‘add_new_item’ => __( ‘Add New Topic’ ),
‘new_item_name’ => __( ‘New Topic Name’ ),
‘menu_name’ => __( ‘Topics’ ),
);
// Now register the taxonomy
register_taxonomy(‘topics’,array(‘post’), array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘topic’ ),
));
}
|
来源:http://www.wazhuti.com/1768.html