+ Reply to Thread
Page 1 of 4
1 2 3 ... LastLast
Results 1 to 10 of 35

Thread: SubCategories

  1. SubCategories

    Does anyone know of a way to introduce subcategories onto a wordpress blog, like using a plug-in? I have a music blog setup and have genres as categories, but would like to have subcategories under genre listed in artists' names or bands.

    Any help would be appreciated.

    Thanks!
    Shawn
    Desty Online -- Bringing offline business practices online. Turning Bloggers into Businessmen.

    The Masked Dispatcher's Video Collection -- Funny, Sexy, Music, and Police Chase Videos

  2. Join Date
    Jul 2007
    Location
    London, UK
    Posts
    1,604

    I don't know of a plugin for that (although I'm sure there will be some) but if you want to do it yourself you can use the get_categories() function.

    Say you are inquiring rock category and it has id 5, you can fetch all subcategories with:

    Code:
    <?php $artists =  get_categories('child_of=5'); ?>
    To make a list of links to these categories you start the list

    Code:
    <ul>
    Then you can iterate $artists to list them all, building the links

    Code:
    foreach ($artists as $artist) {
    	$li = '<li>';
    	$li .= '<a href ="/category/archives/' . $cat->category_nicename . '">';
    	$li .= '$cat->category_nicename';
    	$li = '</a></li>';
    	echo $li;
    }
    End up by closing the list

    Code:
    </ul>
    The whole code, wrapped up in a function, for our own convenience would be like this

    Code:
    <?php
    function show_subcats($cat) {
    	$args = 'child_of=' . $cat;
    	$artists =  get_categories($args);
    	echo '<ul>';
    	foreach ($artists as $artist) {
    		$li = '<li>';
    		$li .= '<a href ="/category/archives/' . $artist->category_nicename . '">';
    		$li .= '$artist->category_nicename';
    		$li = '</a></li>';
    		echo $li;
    	}
    	echo '</ul>';
    }
    ?>
    Call the function for category 5 with

    Code:
    <?php show_subcats(5); ?>
    BE WARNED: the code above wasn't tested, is just a mind dump, it may contain errors. It may even contain an awful lot of them
    Cycling from London to Rochester to Raise Money to build classrooms in Malawi: Donate | Read the Blog

  3. Join Date
    Jul 2007
    Location
    Atlantic Canada
    Posts
    2,986

    Shawn, have you rummaged around in the WordPress.org Plugins directory to see if there's something in there for you?
    http://wordpress.org/extend/plugins/tags/category
    or http://wordpress.org/extend/plugins/tags/categories to start...

  4. Join Date
    Jul 2007
    Location
    Montpelier, Vermont
    Posts
    121

    You already have subcategories in WordPress. You can assign a category to a parent just like a page can have a parent. Whether or not they will display is another matter. It might depend on the code of your theme, but a quick search through template tags should find what you need. I use subcategories on Remarkablogger -- go check 'em out to see them.
    Remarkablogger
    Remarkable blog consulting and coaching

  5. Join Date
    Jul 2007
    Location
    Atlantic Canada
    Posts
    2,986

    Quote Originally Posted by Michael.Martine View Post
    You already have subcategories in WordPress... It might depend on the code of your theme...
    Ah, well, now that explains why I've got subcategories on another blog (with a different theme) and not on Domestik Goddess. You're a veritable fount of useful knowledge!

  6. I didn't find any subcategory plugins, but I did find under manage categories on my wp-admin where I can create subcategories. Now I need to find drop down or expandable category lists or headers for links. I want the subcategories to stay hidden unless you do a roll-over.

    Heh, might be moot, don't know if my theme will display the subcategories yet...

    Thanks for the help all
    Desty Online -- Bringing offline business practices online. Turning Bloggers into Businessmen.

    The Masked Dispatcher's Video Collection -- Funny, Sexy, Music, and Police Chase Videos

  7. Join Date
    Jul 2007
    Location
    London, UK
    Posts
    1,604

    Quote Originally Posted by desty View Post
    (...)Now I need to find drop down or expandable category lists or headers for links (...)

    A drop down on its way, sir!

    PHP Code:
    <?php
    function show_subcats($cat) {
        
    $args 'child_of=' $cat;
        
    $artists =  get_categories($args);
        echo 
    '<select>';
        foreach (
    $artists as $artist) {
            
    $option '<option value="';
            
    $option .= '/category/archives/' $artist->category_nicename '">';
            
    $option .= '$artist->category_nicename';
            
    $option '</option>';
            echo 
    $option;
        }
        echo 
    '</select>';
    }
    ?>
    (disclaimer: again, this code is a mind dump and can contain typos)

    Now, the problem of this approach is that you have to deal with the submission. Ideally, you should assume that your client doesn't have Javascript and put a submit button.

    Then, you could, if you want, use Javascript to remove the submit button and attach an onselect() action so the form submission can be avoided.

    This can be annoying for someone who was looking for a ready made solution, but I find it very strange that isn't a plugin or widget available for download.
    Cycling from London to Rochester to Raise Money to build classrooms in Malawi: Donate | Read the Blog

  8. Join Date
    Jul 2007
    Location
    Montpelier, Vermont
    Posts
    121

    Quote Originally Posted by guioconnor View Post
    A drop down on its way, sir!

    PHP Code:
    <?php
    function show_subcats($cat) {
        
    $args 'child_of=' $cat;
        
    $artists =  get_categories($args);
        echo 
    '<select>';
        foreach (
    $artists as $artist) {
            
    $option '<option value="';
            
    $option .= '/category/archives/' $artist->category_nicename '">';
            
    $option .= '$artist->category_nicename';
            
    $option '</option>';
            echo 
    $option;
        }
        echo 
    '</select>';
    }
    ?>
    (disclaimer: again, this code is a mind dump and can contain typos)

    Now, the problem of this approach is that you have to deal with the submission. Ideally, you should assume that your client doesn't have Javascript and put a submit button.

    Then, you could, if you want, use Javascript to remove the submit button and attach an onselect() action so the form submission can be avoided.

    This can be annoying for someone who was looking for a ready made solution, but I find it very strange that isn't a plugin or widget available for download.
    Nothing gets traffic like having a plugin available for download.
    Remarkablogger
    Remarkable blog consulting and coaching

  9. Join Date
    Jul 2007
    Location
    Atlantic Canada
    Posts
    2,986

    Quote Originally Posted by Michael.Martine View Post
    Nothing gets traffic like having a plugin available for download.
    Yeah, Guilherme, there's a hint for you!
    I could definitely use such a plugin on my association's blog, and I'm sure it would be popular -- very diggable, too?

  10. Join Date
    Jul 2007
    Location
    London, UK
    Posts
    1,604

    Quote Originally Posted by Michael.Martine View Post
    Nothing gets traffic like having a plugin available for download.
    Quote Originally Posted by Jen View Post
    Yeah, Guilherme, there's a hint for you!
    I could definitely use such a plugin on my association's blog, and I'm sure it would be popular -- very diggable, too?
    I was willing to do it, of course, once most of the code is already posted here, but I am caught in so much things to do that I procrastinated.

    Thank you both for the incentive, now I'll code it right away!
    Cycling from London to Rochester to Raise Money to build classrooms in Malawi: Donate | Read the Blog

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts