• Hello all.

    I’m brand new to WP – and to the forums here – so I hope I’m doing everything within the rules. I’ve made some searches but have not been able to find exactly what I’m looking for.

    I built a static website some time ago for my local youth orchestra. Now I want to integrate WP into the site so the committee can look after news updates themselves. For now, I just want to let them put ‘News’ posts on the site’s home page (which consists of a left-hand sidebar and a right-hand ‘main content’ area).

    I have figured out how to make the page ‘WP aware’ and to display posts from a “News” category in the right-hand ‘main content’ area (all while utilising the site’s own styling). So far so good.

    I would now also like to display posts from a “Tidbits” category in the left-hand sidebar.

    So, in my WP admin, I would have 2 mutually exclusive categories: “News” for the main content area and “Tidbits” for the left-hand sidebar.

    I guess I need to have 2 WP loops which will separate the posts from each of the 2 categories? (The “News” loop would go in the main content area div and the “Tidbits” loop would go in the left-hand sidebar div.)

    Could someone suggest a couple of lines of code which could go at the top of each loop so that they would include only the posts from the relevant category?…

    I will really appreciate it if you can help but, as I say, I’m totally new to WP so please don’t make things too techy…

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could try something like this where you populate your left sidebar:

    <?php $my_query = new WP_Query('category_name=Tidbits&posts_per_page=5'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <!-- Do special_cat stuff... -->
    <?php endwhile; ?>

    For reading on multiple loops see The Loop

    Thread Starter cequejecherche

    (@cequejecherche)

    Much appreciated, mydanblog. I’ll give this a go.

    It’s that first line that was beyond my ken at the moment…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘2 loops on 1 page (for posts from 2 different categories)’ is closed to new replies.