WordPress.org

Ready to get started?Download WordPress

Forums

Expanding category? (9 posts)

  1. brettr
    Member
    Posted 7 years ago #

    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

  2. moshu
    Member
    Posted 7 years ago #

    How old is your blog?

  3. Kafkaesqui

    Posted 7 years ago #

    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...

  4. moshu
    Member
    Posted 7 years ago #

    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!]

  5. brettr
    Member
    Posted 7 years ago #

    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.

  6. Kafkaesqui

    Posted 7 years ago #

    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!

  7. brettr
    Member
    Posted 7 years ago #

    Thanks.

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

  8. brettr
    Member
    Posted 7 years ago #

    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.

  9. Kafkaesqui

    Posted 7 years ago #

    "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...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.