• Hi all, how to create this with php?

    – Categories
    — Child Categories
    — Child Categories 1
    — Child Categories 2

    – Categories 2
    — Child Categories
    — Child Categories 1
    — Child Categories 2

    Thanks…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Dannie Herdyawan

    (@k0z3y)

    function publish_categories($args){
    		$taxonomies=get_taxonomies( array('public' => true) , 'names');
    		if (isset($args['allowed_taxonomies'])){
    			$allowed = explode(',',$args['allowed_taxonomies']);
    		} else {
    			$allowed = array('category','post_tag');
    		}
    		$taxonomies = array_intersect( $taxonomies, $allowed );
    		foreach ($taxonomies as $taxonomy ) {
    			$the_tax = get_taxonomy( $taxonomy );
    			$terms = get_terms( $taxonomy , array('hide_empty' => 0));
    			if ($terms) {
    				$array["optgroup_b_{$taxonomy}"] = $the_tax->labels->name;
    				foreach($terms as $term) {
    						$array["" . $term->slug . "#" . $taxonomy . ""] = $term->name;
    				}
    				$array["optgroup_e_{$taxonomy}"] = $the_tax->labels->name;
    			}
    		}
    		return $array;
    	}
    /* set categories */
    				case 'post_categories':
    					$options = publish_categories($args);
    					$res .= "<select name='".$key.'-'.$i.'[]'."' multiple='multiple' class='chosen-select' data-custom-error='".__('Please choose a category at least','userpro')."' data-required='".$args['require_category']."' data-placeholder='".$placeholder."'>";
    					foreach($options as $k=>$v) {
    						if (strstr($k, 'optgroup_b')) {
    							$res .= "<optgroup label='$v'>";
    						} elseif (strstr($k, 'optgroup_e')) {
    							$res .= "</optgroup>";
    						} else {
    							$res .= "<option value='$k'>$v</option>";
    						}
    					}
    					$res .= "</select>";
    					break;

    WordPress by default allows you to assign categories to other categories as children. Just go to the POSTS/CATEGORIES dashboard.

    Thread Starter Dannie Herdyawan

    (@k0z3y)

    I want create frontend publisher, so member can post on frontend. And i want show all categories with dropdown like this:

    – Categories
    — Child Categories
    — Child Categories 1
    — Child Categories 2

    – Categories 2
    — Child Categories
    — Child Categories 1
    — Child Categories 2

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘About Categories’ is closed to new replies.