Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Custom Taxonomy in Wordpress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 269
    Comment on it

    Hello reader's today we will discuss about "Custom Admin Dashboard Menu or Custom Taxonomies".

    WordPress provides a new method of grouping content by allowing you to create your own custom taxonomies. The core developers have created the register_taxonomy() function.

    A taxonomy is a group of terms. Terms are individual choices. For example, Post Tags is a taxonomy, and each tag is a term within that taxonomy. They cannot conflict to other taxonomy.

    example :- If you want to create a custom gallery in admin dashboard the code is below. And use register_taxonomy() to register your taxonomy.

        <!--?php
            /******* Custom Code for adding taxonomy *********/
    
            add_action( 'init', 'themename_gallery_content_init' );
            function themename_gallery_content_init() {
                $labels = array(
                    'name'                          =--> _x( 'GALLERY', '' ),
                    'singular_name'                 =>_x( 'GALLERY', '' ),
                    'menu_name'                     => _x( 'GALLERY', '' ),
                    'name_admin_bar'                => _x( 'GALLERY', '' ),
                    'add_new'                       => _x( 'Add New', '' ),
                    'add_new_item'                  => __( 'Add New GALLERY', '' ),
                    'new_item'                      => __( 'New GALLERY', '' ),
                    'edit_item'                     => __( 'Edit GALLERY', '' ),
                    'view_item'                     => __( 'View GALLERY', '' ),
                    'all_items'                     => __( 'All GALLERY', '' ),
                    'search_items'                  => __( 'Search GALLERY', '' ),
                    'parent_item_colon'             => __( 'Parent GALLERY:', '' ),
                    'not_found'                     => __( 'No GALLERY found.', '' ),
                    'not_found_in_trash'            => __( 'No GALLERY found in Trash.', '' )
                );
    
            $args = array(
                'labels'                        => $labels,
                'menu_icon'                     => 'dashicons-editor-textcolor',
                'public'                        => true,
                'publicly_queryable'            => true,
                'show_ui'                       => true,
                'show_in_menu'                  => true,
                'query_var'                     => true,
                'rewrite'                       => array( 'slug' => 'gallery' ),
                'capability_type'               => 'post',
                'has_archive'                   => true,
                'hierarchical'                  => false,
                'menu_position'                 => 6,
                'supports'                      => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
            );
    
            register_post_type( 'gallery', $args );
        }
    
    
    add_action( 'init', 'themename_gallery_category_taxonomy_init', 0 );
    
    function drhersh_gallery_category_taxonomy_init() {
    
        $labels = array(
            'name'                          => _x( 'GALLERY Category', 'taxonomy general name' ),
            'singular_name'                => _x( 'GALLERY Category', 'taxonomy singular name' ),
            'search_tems'                  => __( 'Search GALLERY Category' ),
            'all_items'                     => __( 'All GALLERY Category' ),
            'parent_item'                   => __( 'Parent GALLERY Category' ),
            'parent_item_colon'             => __( 'Parent GALLERY Category:' ),
            'edit_item'                     => __( 'Edit GALLERY Category' ),
            'update_item'                   => __( 'Update GALLERY Category' ),
            'add_new_item'                  => __( 'Add New GALLERY Category' ),
            'new_item_name'                 => __( 'New Genre GALLERY Category' ),
            'menu_name'                     => __( 'GALLERY Category' ),
        );
    
        $args = array(
            'hierarchical'                  => true,
            'labels'                        => $labels,
            'show_ui'                       => true,
            'show_admin_column'             => true,
            'query_var'                     => true,
            'rewrite'                       => array( 'slug' => 'gallery-category' ),
        );
        register_taxonomy( 'gallery-category', array( 'gallery' ), $args );
    }
    
    /******* End Custom Code for adding taxonomy *********/
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: