WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to display posts from category and sucategory (3 posts)

  1. danielpol
    Member
    Posted 3 years ago #

    Hi, I'm quite new to WP and not really a coder

    I have several categories and subcategories on a WP site and when a parent category is selected i want to display the post in it and also the posts from its children.
    the problem is that the code I have now http://pastebin.com/1Q4RSKFi it shows only the posts from child category and if there is no child category it works just fine, I mean it shows all the posts from current category
    Any help appreciated.
    Thanks

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

    when a parent category is selected

    how does the category get selected?
    is it essential that it is a parent category?
    what template is using this code?

    get_the_category() will get the categories of the current post (which might not be what you want ?):
    http://codex.wordpress.org/Function_Reference/get_the_category

    if this is a category archive, get_query_var('cat') would get the selected category;

    you could use this in the query:

    $catg = new WP_Query('post_type=>any&cat=' . get_query_var('cat').'&orderby=date&order=desc&showposts=100');

    (no foreach needed)

  3. danielpol
    Member
    Posted 3 years ago #

    when a parent category is selected

    i mean when you click on it

    what template is using this code?

    this would be category.php

    ..but your solution actually works. Thanks alchymyth. I owe you.

    And if we're here maybe you can help me with my other issue. I have the calendar widget and i want to display the posts from a specific day.
    I supose I'll have to create date.php.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.