WordPress.org

Ready to get started?Download WordPress

Forums

How To show the post titles of a currently opened category in my sidebar (3 posts)

  1. tjdesign
    Member
    Posted 2 years ago #

    Hi,

    I'm just creating a page for a client and I need some help with categories and post-titles.

    I created some categories which are displayed as <?php wp_list_categories('title_li=&include=4,9,17,19,20'); ?> in my sidebar.
    When i click a category i see the posts that are in the "current" category. Everything works fine.
    But its a long way to scroll to see all of them.

    Is there any possibility, after I click on the category I want to browse, to display the post titles that are in that category like:

    category a
    category b (clicked)
    post title 1
    post title 2
    post title 3
    category c
    category d
    etc...

    but when I i.e. click on category a i want to display only post titles that are in category a in my sidebar, like:

    category a (clicked)
    post title 1
    post title 2
    post title 3
    category b
    category c
    category d
    etc, etc..

    Please help me because I really don't know how to do this.

  2. chadrew
    Member
    Posted 2 years ago #

    So you want a sort of expandable post list. I think you could get post lists for all your categories in the sidebar first, then hide them using CSS (display: none;). And then use a simple JavaScript toggle which happens when you click a category link, to "unhide" them.

    Makes sense? But don't ask me to actually write it all since I haven't done anything like this before :)

    Edit: there are lots of toggle code examples online, like this:

    http://circlecube.com/2007/11/javascript-code-to-show-a-hidden-element/

  3. tjdesign
    Member
    Posted 2 years ago #

    hmm i thought about some php something like

    <?php wp_list_categories('title_li=&include=3,5,6,8,7'); ?>
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

    This works but the titles are displayed like:
    category a (clicked)
    category b
    category c
    post title a (category a)
    post title b (category a)
    post title c (category a)

    thats not really good looking and it makes no sense

    and when i click on a post the category post titles disappear the only one thats staying is the one i'm on....

Topic Closed

This topic has been closed to new replies.

About this Topic