Support » How-To and Troubleshooting » Two categories on one page – need help.

Two categories on one page – need help.

  • I currently have one category that posts to a page. I’d like to have two categories post to the same page.

    I have this bit of code that someone else had already put in the page…

    $args = 'category_name=appearances&author=' . $curauth->ID . 'showposts=100&order=ASC';
    if (have_posts()) {
    while (have_posts()) {
    the_post(); ?>
    <strong><? echo get('appearance_date'); ?>: <? the_title(); ?></strong>
    <? the_content(); ?>

    that’s on the author.php page…

    the category-news.php page that all the “news” categories post to has this bit of code..

    while(have_posts()) {

    I’d like to have all posts that have a blog category to also post to the category-news.php page as well….is it possible? and if so, how?

    thanks much for any advice!


Viewing 13 replies - 1 through 13 (of 13 total)
  • Hmm… The reason the news is posting to that particular page is that you are using a category template “category-news” where news is actually the category. Try replacing

    		while(have_posts()) {


    <?php $my_query = new WP_Query('category_name=news,blog');
      while ($my_query->have_posts()) : $my_query->the_post();

    Make sure that the categories are correct and use the category slug, not the category name.

    ok..I tried that and got a syntax error…I’m thinking I have one of these <? wrong..I’m replacing

    		while(have_posts()) {


    <?php $my_query = new WP_Query('category_name=news,blog');
      while ($my_query->have_posts()) : $my_query->the_post();

    does it need another ?> at the end?

    sorry…I’m still learning. =)

    yep is sure does… i apologize. heres the corrected code:

    <?php $my_query = new WP_Query('category_name=news,blog');
      while ($my_query->have_posts()) : $my_query->the_post(); ?>

    Sorry, still getting syntax errors…
    I’ve posted the entire page in pastebin
    ….when I put in the code above, it said error in line 13 an unexpected ‘}’….then when I took that bracket out, it said unexpected $end in line 26.

    sorry to be a pest. =)

    OH I see….(sort of) in my first example there’s a ‘{‘ that then ends later in the code…but there’s no answering ‘}’ in your snippet of code…
    I have NO idea how to fix that….=) but I see it!

    oh don’t leave me now…..

    Sorry… Try this and let me know how it goes.


    it worked!!! I love you!!!!!!!!!!!!!!!!!!!!
    thank you thank you thank you!!!!!!!!

    oh ohoh! one more thing….is there a way to allow comments to be added? or is that not possible since it’s a category only page?

    Glad it worked.

    Its possible to show comments on an archive(category) page. You’ll need to play around with the template tags to get things how you want them. Check this link in the codex:


    First try placing <?php comment_form(); ?> right before the loop ends. That is, right before the <?php endwhile; wp_reset_postdata(); // End the loop ?> line.

    The while(have_posts()) starts the loop and the endwhile; ends the loop.

    Let me know if that works.

    Ok..added it in before the end loop…but nothing changed. do I need to add a comment field? or?

    This piece of code

    <?php global $withcomments;

    almost works, as it brings up a Comments are Closed post at the end of each category…..any thoughts of how to change that to open?

    appreciate your help!


    Im pretty sure the comments are closed thing means that comments have been disabled for either all blog posts or for that specific post. Check in wp-admin settings-discussion for the global comment settings, then each blog post or page will have individual settings in case you want to allow or disallow comments on a specific post.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Two categories on one page – need help.’ is closed to new replies.
Skip to toolbar