WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show only that specific category and it's posts - nothing else (4 posts)

  1. diad
    Member
    Posted 6 years ago #

    I am thinking this is done with a nested loop so I am afraid to get into it because I know they are complicated. I want this:

    Click a category.
    Sidebar shows only that category, it's children and posts that are in those. It doesn't show all of the categories or all of the posts, only the ones that are specific to that page.

    We are on post 2 page:

    Category
    Child1 of Category
    post 1
    post 2 (this is the page we are on now)
    post 3
    Child2 of Category
    (posts of child2 category are collapsed)

  2. diad
    Member
    Posted 6 years ago #

    Ok, I've figured out a little. Haven't gotten to the collapse part or even showing the individual posts under the children but I at least have a loop that shows only the present category, it's children and the number of posts.

    I simply did:

    <?php single_cat_title('Currently browsing '); ?>
    	<?php if ( in_category('2') )
    	echo wp_list_categories('orderby=id&show_count=1
    &use_desc_for_title=1&child_of=2'); ?>

    I had to pick the specific category and will have to change the '2' to whatever the parent category is but I don't plan on having more than a few. I'm just going to change currentyl browsing to blank so it only shows the title.

  3. diad
    Member
    Posted 6 years ago #

    If I could only get the second loop to go inside the first one. The way this code below comes out is like this:

    Child Category
    Child Category
    Child Category

    "Individual Posts in (the child category)"

    Post1
    Post2
    Post3

    It is doing a good job of only showing the posts of the category it in but I can't get the parent category to show at the top and I want the posts underneath it's child. I'm sure there are other code mistakes...

    <h2>Categories</h2>
    
    <ul><li>	
    
    <?php if ( in_category('2') )
    	echo wp_list_cats('orderby=id&show_count=0
    &use_desc_for_title=1&child_of=2'); ?> 
    
    </li></ul>
    
    	<?php single_cat_title('Individual Posts in '); ?>
      <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
         <div class="post">
         <div id="post-<?php the_ID(); ?>"><ul><li>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li></ul></div>
        <?php endwhile; ?>
  4. diad
    Member
    Posted 6 years ago #

    Wow, well, I've finally come up with a solution. I was wanting for a way to have pages show only specific posts. Sort of as a holder or vessel for specific posts. After attempting all kinds of sidebar hacks I finally have a way to do it, not perfect, but at least it's easier. I use redirectify.

    Basically have your page forward to the archive/category tag, not the post tag or anything. Then you can call you page the same thing you call the category, like my ART GALLERY page goes to the ART GALLERY category, and lists all the art shows I have had and all their galleries.

    I will probably use some of the techniques above to show the menu of the parent and children pages by having the specific pages use specific templates.

    whew

Topic Closed

This topic has been closed to new replies.

About this Topic