Support » Themes and Templates » How to make Home Page show posts from 1 Cat & child cats?

  • Hi everyone

    I know there has to be a simple way to do this and I’ve spent days reading up on template tags and conditional tags – in the codex and here in the forums and I cannot figure out how to do this.

    First though, this is not related to a sidebar list of categories and restricting them to a child cats list using list_categories() – I know how to use the “child_of=()” argument with that, and have done so successfully.

    This relates to the posts shown on the home page (not front page) and the subsequent pages in the list for homepage. The theme I’m using (Vina) has an excellent and working conditional page lay-up depending on whether the page is home first page, home pages a to b, pages c to d and so on. I’m using that and it works great.

    However, the default code for the queries and loops assumes that you’re querying ALL post categories and their dependents – the site works great right now because I only have one top level post category, then a deep and wide hierarchy below it,

    What I now want to do is have additional top level post categories, but exclude all the new ones from the front page. Everything I’ve read for the various exclude=() parameters indicate the need for an extensive (and tediously manually maintained) array of each individual category to be excluded. There is no mention that excluding a high level post category will exclude its child categories. The same applies with the include=() parameters.

    Thos omissions are true whether using WP_query() or get_categories() or get_posts() or whatever.

    I’m sure I’ve missed something blindingly obvious – I must have, because I cannot believe Automattic have not made this functionality to be easy to use. But I just can’t see it or get it.

    Essentially, what I want to use is something along the lines of –
    – if is_home() include only category(x) and_its_children
    – do the page based options from the loop here
    – endif

    Yeah, I know that’s not code, but it’s the intended result.

    Can anyone give me the template tag and structure I need for that “if is_home ….” line please?

Viewing 1 replies (of 1 total)
  • Put this in your index.php before the loop:

    <?php if ( is_home() ) {
    query_posts($query_string . '&cat=3');

    where 3 is the category you want to show.
    If you want more categories just insert them separated by comas.

    Another way to do the same thing:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=3&posts_per_page='.get_option('posts_per_page').'&paged=' . $paged);

Viewing 1 replies (of 1 total)
  • The topic ‘How to make Home Page show posts from 1 Cat & child cats?’ is closed to new replies.