Support » Fixing WordPress » Expanding category?

  • I’d like to display each post within a category once the user clicks that category, all in the sidebar. For example, the user clicks a category and each post will display under that category (indented), pushing down the other categories to make room.

    Is there a way to do it in code or a plugin that already does it?

    Thanks,
    Brett

Viewing 8 replies - 1 through 8 (of 8 total)
  • How old is your blog?

    So you want to visit Category 1 and see this in your sidebar:

    Category 1
    – Cat 1 post
    – Cat 1 post
    Category 2
    Category 3

    Then visit Category 2, and see:

    Category 1
    Category 2
    – Cat 2 post
    – Cat 2 post
    – Cat 2 post
    Category 3

    Hmm. This may fit the bill:
    http://wordpress.pastebin.ca/241315

    Note your post list for any category could get pretty long, depending on the number of posts under it…

    Note your post list for any category could get pretty long, depending on the number of posts under it…

    That was exactly my point 🙂
    These ideas always seem so bright while you set up your blog and have 4 posts… but imagine a blog with 7009 posts in 4 categories [BTW, this is a real number for a blog I helped to move from blogger last year!]

    I understand it can get really long.

    The code works great! What do I need for displaying the post count in parantheses next to each category? The code is missing that part.

    Put this where you want the post count to appear:

    <?php echo $category->category_count; ?>

    (I left it off because I figured, Hey, just count the posts! ;)

    moshu: 7009? Now *that’s* an exact number!

    Thanks.

    This gives the count for the particular category: http://wordpress.org/support/topic/12805?replies=5#post-424730

    I don’t know if the code that makes this work:

    Category 1
    Category 2
    – Cat 2 post
    – Cat 2 post
    – Cat 2 post
    Category 3

    is supposed to collapse everything when “Cat 2 Post” is clicked. Does that sound right? Mine only expands when the category title is clicked. Otherwise, it remains collapsed.

    I also notice when I click an expanded post title, these two have no values:

    $category->cat_ID
    $cat

    After clicking a category title, they do have values.

    is supposed to collapse everything when “Cat 2 Post” is clicked. Does that sound right?

    It collapses as there is no longer a value for $cat. That particular var is only extant as long as one is on a category query.

    Anyway, this mod to the code linked above keeps the post list ‘open’ on a single post page:

    http://wordpress.pastebin.ca/242658

    Note that it will select the first category on a post. So if you assign more than one category, it may not work as expected…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Expanding category?’ is closed to new replies.