WordPress.org

Ready to get started?Download WordPress

Forums

Exclude posts for child categories from parent category (8 posts)

  1. DStall
    Member
    Posted 4 years ago #

    I'm only assigning 1 category to post, either child or parent category.
    Currently, when listing posts for parent category, all posts in child categories are returned as well.

    How can I modify code in wp category-template.php core file (or other file) to exclude posts for child categories from parent category?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    http://codex.wordpress.org/Template_Tags/in_category

    And I'd strongly recommend modifying your category templates rather than any core files.

  3. DStall
    Member
    Posted 4 years ago #

    Since the only categories that don't function as I'd like are parent categories, are you suggesting that I create category templates for the parent categories in order to exclude the child category posts from the parent category posts?

    I've never created a category template, and instructions at link you posted are over my head.

    Could you please upload a sample category template and post code to be added to it for excluding child posts with instructions on where to add code and what code (if any) to delete?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

  5. DStall
    Member
    Posted 4 years ago #

    I can create a category template but have no idea what code to put in it (other than duplicating code from archive.php file).

    Could you please, please, please!!! post an example of a category template with sample code for excluding child category from parent category.

    The links to wordpress files don't help.

  6. MichaelH
    Member
    Posted 4 years ago #

    Call me a glutton for punishment but will add this one more time--meaning others will have to follow-up if there are questions.

    Please note...deactivate all plugins and switch to the WordPress Default theme. Then in the wp-content/themes/default folder create a file called category.php and put this code in that category.php:

    http://wordpress.pastebin.com/s5r6yExY

    Then visit a parent category to see the results.

    As a note, by WordPress standards, ANY category that has been designated a Parent category is not meant to be checked in the category hierarchy when writing posts. Meaning, only the latest generation category should be checked. Think of it like this, only the youngest generation gets the action.

    Over and out. Good Luck

  7. DStall
    Member
    Posted 4 years ago #

    I'm not checking the parent category AND the child category, I'm assigning some posts the parent category and others the child category of the parent.

    So why do the child category posts show up in the parent category list of posts?

  8. Jennifer
    Member
    Posted 3 years ago #

    This is exactly what I need to know as well. Did you ever find an answer? Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.