WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Include specific category + children in index.php loop (6 posts)

  1. novice21
    Member
    Posted 7 years ago #

    Hey guys!

    Here's what I want to do. In the Index.php page, I'd like the following logic to be carried out:

    If have posts...while have posts...
    PRINT EXCERPT OF CATEGORY 1 (and child cats in cat1)
    PRINT EXCERPT OF CATEGORY 2 (and child cats in cat2)
    PRINT EXCERPT OF CATEGORY 3 (and child cats in cat3)
    endwhile;
    Print navigation
    Else:
    No posts found.
    endif;

    I'm stuck on the print part, I can do everything else. I don't want the loop to print cat 1 and 2 and 3, I want it to print cat 1, then cat2, then cat 3, including the children cats of each parent category called. I'm styling differently and need the output of each cat grouped neatly together so my page flows properly.

    Codex only talks about excluding categories...thats really hard to work with in my case because I'd like to call a specific category, I'm pretty sure there's a way to do it, through a count increment or something? I read the multi-loop page in codex but it feels like what I'm trying to do can't be done. My programing skills are so-so, I can't really write code, I can follow its logic though....so any thoughts? Can it be done?

    (This is not a static Page, its my Index.php page)

  2. Adam Brown
    Member
    Posted 7 years ago #

    I've seen a few other forum posts about this recently. Search.

    I also saw a plugin that will display the first few posts from each category. Might want to look there too.

  3. novice21
    Member
    Posted 7 years ago #

    What other forum posts? All the one's I've seen seem to want to hide a category completely, I looked again and nothing's really getting me going except for Codex. I don't want to hide anything, I simply want my posts on the main page to be grouped by category, they're only three parent categories I want to display. I just need to temporarly hide cats for printing.

    I'm sorta getting it done, but it's weird because its NOT supposed to work the way I've done it according to codex? From what I understand you can't duplicate a loop without resting the count using <?php rewind_posts() ?> But its working for me, weird?

    I'd solve the whole thing if I could undo the value I set for query_posts. For example, if I wrote:
    set query_posts('cat=-1');

    How would I undo this later? so its not looking at that value? what is the default value anyhow?

    Is there ANY way to get in_category('1') && in_category('2') to work? && means AND right? || means OR.

    Thanks.

  4. rudolf45
    Member
    Posted 7 years ago #

    What other forum posts?
    For starters... http://wordpress.org/support/topic/38046?replies=53

  5. Chris_K
    Member
    Posted 7 years ago #

  6. novice21
    Member
    Posted 7 years ago #

    Awesome links guys, I really appreciate this.

    The link rudolf gave me is exactly what I want!! The only adjustment I need to make is to provide an alternate div wrapper around the post divs for a certain category and I'll be set to go, I have NO idea how to do that however... any ideas on the best way to contact the poster about this? Would posting in the topic do any good if its old?

    The link you gave me HandySolo solved some of my confusion with the query posts function, thanks! Its a nice fall back in case this doesn't work out... it doesn't seem like I could use navigation to browse the next 10 entries or whatever number of posts I choose..

    Again, thanks a bunch guys!!

    Edit: Hm... that topic is closed...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags