WordPress.org

Ready to get started?Download WordPress

Forums

Two categories on one page - need help. (14 posts)

  1. intcon
    Member
    Posted 1 year ago #

    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';
    query_posts($args);
    if (have_posts()) {
    while (have_posts()) {
    the_post(); ?>
    <li>
    <strong><? echo get('appearance_date'); ?>: <? the_title(); ?></strong>
    <? the_content(); ?>
    </li>

    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()) {
    the_post();
    ?>

    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!

    carrie

  2. imikedesigns
    Member
    Posted 1 year ago #

    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()) {
    			the_post();
    ?>

    with

    <?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.

  3. intcon
    Member
    Posted 1 year ago #

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

    <?
    		while(have_posts()) {
    			the_post();
    ?>

    with

    <?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. =)

  4. imikedesigns
    Member
    Posted 1 year ago #

    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(); ?>
  5. intcon
    Member
    Posted 1 year ago #

    Sorry, still getting syntax errors...
    I've posted the entire page in pastebin
    http://pastebin.com/s6NAtSLn
    ....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. =)

  6. intcon
    Member
    Posted 1 year ago #

    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!

  7. intcon
    Member
    Posted 1 year ago #

    oh don't leave me now.....

  8. imikedesigns
    Member
    Posted 1 year ago #

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

    http://pastebin.com/TJg9v8cH

  9. intcon
    Member
    Posted 1 year ago #

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

  10. intcon
    Member
    Posted 1 year ago #

    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?

  11. imikedesigns
    Member
    Posted 1 year ago #

    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:

    http://codex.wordpress.org/Template_Tags#Comment_tags

    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.

  12. intcon
    Member
    Posted 1 year ago #

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

  13. intcon
    Member
    Posted 1 year ago #

    This piece of code

    <?php global $withcomments;
    $withcomments=1;
    comments_template();?>

    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!

    =)

  14. imikedesigns
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.