WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category/Subcategory Display Issues (13 posts)

  1. fishfinder
    Member
    Posted 3 years ago #

    Hey Folks,

    I've been searching for hours to solve this one, but just can't find a hack to get it right!

    I'd rather not use a plugin for this, but simply hard code it into my template files.

    Here's the scenario:

    My categories have subcategories. All posts are in the sub categories with the exception of a few.

    I'd like my archives pages for categories to show subcategory links, which link to the subcategory page. I want a list of posts only to display on the subcategory page, unless the parent category has posts in it, which would be displayed on the category page.

    Example:

    1st category page:
    CATEGORY 1
    -----SUB CAT 1
    -----SUB CAT 2
    -----SUB CAT 3
    (only show posts here if they are categorized by the parent category)

    Click on a sub category and get its page with posts:
    SUB CAT 1
    ------POST 1
    ------POST 2
    ------POST 3
    etc.
    (show posts of SUB CAT 1 here)

    Hopefully that makes a little bit of sense!

    Dave

  2. fishfinder
    Member
    Posted 3 years ago #

    Still hoping to get some help with this!

    Basically looking for some code that would say:

    if category, show subcategories

    If subcategory, show posts.

    that kind of thing....

    thanks,
    Dave

  3. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    this will check if the category in the archive is top category:
    then show the list of child categories, and any direct posts in the category;
    if not show the posts.

    the snippet is put before the actual loop in category.php:

    <?php $this_cat = get_query_var('cat');
    if(!get_category($this_cat)->category_parent) : //check if this is top-category
    wp_list_categories('title_li=&child_of=' . $this_cat . '&show_option_none=');
    $args = array(
    'category__in' => $this_cat,
    'paged' => get_query_var('paged')
    ); //prepare to show only direct post of this category
    query_posts( $args );
    endif; // end of check ?>

    it does not check if there are posts directly in this cat, this is left to the loop; you therefore might need to make extra arangements for the 'not found' part of the loop.

  4. fishfinder
    Member
    Posted 3 years ago #

    Hi Alchymyth,

    That is perfect, except just one thing. Can we prevent that from listing them?

    Here is the full code that I'm using, including what you have posted above.

    [code moderated as per forum rules - please use the pastebin]

    http://pastebin.com/i4DNsmVy

  5. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    Can we prevent that from listing them?

    what specidfic do you mean?

    listing what not?

  6. fishfinder
    Member
    Posted 3 years ago #

    Oh, sorry, here's a link to one of the pages


    Site

    you'll see there is a bulleted list of the subcategories above the list of subcategories that I've already put in there.

    I'd like to either remove the bulleted list above mine, or simply style your list based on what mine currently looks like

    thanks man, this is much appreciated!

    dave

  7. fishfinder
    Member
    Posted 3 years ago #

    Its in the center of the page, right below the ads.

    The site is not live, so I'm not worried about messing with code even if there are problems

  8. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    your code sorted and with the conditional included:

    http://pastebin.com/yQK28u5X

  9. fishfinder
    Member
    Posted 3 years ago #

    Hey Alch,

    I can see that this is moving in the right direction, but still not quite there.

    Its still listing posts on the parent category page. Except now its list all posts in order by date.

    I'm hoping to have the posts only showing up on the sub category pages, and have them include the thumbnail and the description.

    site

    thanks for this my friend!

  10. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    my bad - changed one bit - forgot the other:

    this here:

    <?php $args = array(
    'category__in' => $this_cat,

    should be:

    <?php $args = array(
    'category__in' => $cat,

    full template: http://pastebin.com/TWxE0dHE

  11. fishfinder
    Member
    Posted 3 years ago #

    Wow buddy!!!

    Thats exactly it!

    This was one of the last hurdles in getting this site ready to roll. Its replacing a horrible Joomla site that is currently being used.

    Thanks so much man!

    Dave

  12. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    you are welcome ;-)

    if this is all sorted, please mark this thread as 'resolved' - thanks

  13. fishfinder
    Member
    Posted 3 years ago #

    Yup, I was just waiting to see if you posted here again.

    Resolved, and thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic