• Resolved gward1

    (@gward1)


    Hello,

    The website I’m working on is going to have hundreds if not thousands of categories and sub categories so I need to have them organized well.

    Is there a plugin that will list the sub categories on each category page? I would prefer this because I’m using the extended categories plugin which lists select categories (top level only) in a widget. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • For use in category template to list child categories– if no child categories list whatever

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      $child_cats = get_categories('child_of='.$cat);
      if ($child_cats) {
        $args = array(
          'title_li' => '',
          'echo' => 1,
          'child_of' => $cat
        );
        wp_list_categories($args);
      } else {
        //do whatever if no child cats like do a post loop
      }
    }
    ?>

    Thread Starter gward1

    (@gward1)

    I found this code on a different website and it seems to be doing what I want with a few exceptions.

    [code]
    <?php

    // outputs subcategories in same way, if there are any (if you're browsing a parental category)

    $has_children = (bool)(get_category_children(intval(get_query_var('cat'))));

    if (is_category() AND $has_children) {
    wp_list_categories('title_li=<h2>Alphabetical Listing of Artists</h2>&child_of=' . intval(get_query_var('cat')));
    }

    ?>
    [/code]

    However it puts a bullet next to the title_li, which I don’t want because it looks weird. You can see what I mean on this page: http://www.songlyricsx.com/lyrics/a/.

    Here’s the code for the posting part which is displayed above the current subcategories:

    [code]
    <div class="middle">

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div id="post-<?php the_ID(); ?>">
    <h2>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    <p><small><?php the_time('F jS, Y') ?> <?php the_author() ?></small> Posted in <?php the_category(', ') ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', '', ' | '); ?> <?php if(function_exists('the_views')) { the_views(); } ?></p>

    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>

    <!-- AddThis Bookmark Post Button BEGIN -->
    <?php echo "<div class=\"addthis\"><img src=\"http://s9.addthis.com/button1-bm.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"AddThis Social Bookmark Button\" /></div>"; ?>
    <!-- AddThis Bookmark Post Button END -->
    [/code]

    How do I modify this so that if it’s a parent category no post is shown and if it’s a child category it shows the posts? Thanks!

    Please paste ALL the code from that template file into a pastebin such as wordpress.pastebin.com, and report the link back here. Maybe someone can spot your problem. Thanks.

    Thread Starter gward1

    (@gward1)

    Hello,

    I figured it out by incorporating your code. The last thing is what do I need to change to make it so that if there are 100 subcategories it will go to another page? Is this possible? The code can be found here for category.php: http://wordpress.pastebin.com/m97fa786

    Thanks.

    I’ve not found a way to paginate wp_list_categories.

    Thread Starter gward1

    (@gward1)

    Bummer, thanks for the help though.

    Thread Starter gward1

    (@gward1)

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Sub Categories Links’ is closed to new replies.