• I’m creating a blog for book reviews. I’ve created four major categories: year, publisher, author, and topic. But these are all displayed in one long (!) list. Instead of displaying one list called categories, I’d like to be able to display four separate lists. In short, I want four or more separate category lists. Is there a way to do this? I’d appreciate any suggestions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I have the same desire, and would appreciate help. Instead of using a parent and sub-category structure, I would like an additional form element (of the category type) for my posts. I have seen plug-ins that allow for the creation of certain form elements, but nothing of the category type, and nothing that would add the second side bar. Any help appreciated.

    Here is what I did:

    function catbyAuthor($author_id) {
    		global $wpdb;
    
    	$sql = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_author = $author_id";
    	$posts = $wpdb->get_results($sql);
    
    	$counter = 0;
    	$sql = "SELECT category_id FROM $wpdb->post2cat WHERE ";
    	foreach ($posts as $post) {
    		$sql .= ($counter > 0) ? " OR " : "";
    		$sql .= "post_id = $post->ID";
    		$counter++;
    	}
    	$cats = $wpdb->get_results($sql);
    
    	$inc_array = array();
    	foreach ($cats as $cat) {
    		array_push($inc_array, $cat->category_id);
    	}
    	$inc_array = array_unique($inc_array);
    	sort($inc_array);
    	$includes = implode(',', $inc_array);
    	wp_list_categories('title_li=&include='.$includes);
    }

    That could be expanded on a lot as well.

    So the basic idea is that it finds out all the post_ids of posts by a specific author. It then uses those to find all the category_ids of each of those posts.

    The last part is to remove any duplicate category_ids and sort them so that they are in ascending order.

    It then uses the new variable for the include argument of the wp_list_categories function. you could also add arguments to the function for any of the arguments in the wp_list_categories so that you have full functionality within this function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying Categories in Separate Groups/Lists’ is closed to new replies.