Grouping categories by genre

It sounds to me like genre should be its own taxonomy. Then posts get assigned to both categories and genres. If you do it this way, here’s what you need to do to get everything working: First, register the taxonomy genre. Next, assuming you’re using the core posts and categories, go to Settings → Permalinks. … Read more

Make parent category an optgroup

You will need to extend the Walker_CategoryDropdown walker. A very, very simple version of that is this: class Top_level_Optgroup extends Walker_CategoryDropdown { var $optgroup = false; function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { $pad = str_repeat(‘ ’, $depth * 3); $cat_name = apply_filters(‘list_cats’, $category->name, $category); if (0 == … Read more

Remove the parent name from permalink

Add this code to your functions.php, add_action( ‘init’, ‘build_taxonomies’, 0 ); function build_taxonomies() { register_taxonomy( ‘category’, ‘post’, array( ‘hierarchical’ => true, ‘update_count_callback’ => ‘_update_post_term_count’, ‘query_var’ => ‘category_name’, ‘rewrite’ => did_action( ‘init’ ) ? array( ‘hierarchical’ => false, ‘slug’ => get_option(‘category_base’) ? get_option(‘category_base’) : ‘category’, ‘with_front’ => false) : false, ‘public’ => true, ‘show_ui’ => true, … Read more

How to list all categories in three divs dynamically based on the quatity of categories?

You can use get_categories() function. <?php $cats = get_categories(); $count = 15; // Total Categorie $linetotal=round($count/3); ?> // Part of Categorie <div class=”category_list”> <ul><?php $totalcount = 1; $totalpart = 1; foreach($cats as $cat): ?> <li><?php echo $cat->name; ?></li><?php if($totalcount % $linetotal == 0 && $totalpart < 3) { echo ‘</ul></div><div class=”category_list”><ul>’; $totalpart++; } $totalcount++; endforeach;?> … Read more

Get category URL knowing it’s id

If you have category ID you can create link to category like below : <a href=”https://wordpress.stackexchange.com/index.php?cat=7″>Category Title</a> For more details read from this link : https://codex.wordpress.org/Linking_Posts_Pages_and_Categories Thanks!

Exclude current post from loop

Try this: For your single-accessory.php template: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php // excludes this post from ‘Related posts’ in the sidebar $GLOBALS[‘current_id’] = $post->ID; ?> For your sidebar or where you want to show related posts: <?php if (is_singular(‘accessory’) ) : global $post; $categories = get_the_category(); $exclude = $GLOBALS[‘current_id’]; $args … Read more

Custom taxonomy template for categories

Your terminology is a bit scrambled here. A custom taxonomy is a taxonomy which you manually register through register_taxonomy. In your case that is ait-dir-item-category. Any “category” (as you call it) you create in your custom taxonomy is called a term. In this case events. To create a custom page for events, you need to … Read more