如何为wordpress主题新添加一组自定义分类


此功能文章类目纵向管理,在wordpress主题的使用中单线的文章分类可能不足以组织目前的文章类别,所以我们需要再添加一组新的分类功能,那下面的代码就可以轻松实现那说到底这个功能的使用场景是怎样的呢,通常情况下,这个功能只出现在专题中,也就是说,这个功能的延伸是专题开发。大家可以综合利用一下。

把以下代码复制到functions.php文本始就可以生效为一个topics的分类选项组,而且自动调用的文章列表及菜单中

161718192021222324252627282930313233343536//hook into the init action and call create_book_taxonomies when it firesadd_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' ),)); }

上一篇:wordpress文章形式判断页面函数代码

下一篇:wordpress文章如何按浏览量排序


wordpress主题
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器