• Hi – I’d appreciate a hand with this as I’ve been trying for hours!

    I have a page about oranges. It has a bit of text that can be updated using the CMS.

    On that page I want to pull in posts with “oranges” set as their category. I want to allow people to comment on the page at the bottom of it.

    So I have

    <?php while (have_posts()) : the_post();  ?>
    This shows text from cms
    <?php endwhile; ?>
    
    <?php query_posts(category_name=oranges'); ?>
    list all posts with orange category
    <?php endwhile; ?>
    
    comments_template();

    This works except if the last post has comments disabled it passes that info from the first loop to the 2nd so disables comments for the whole page.

    Reading the page on the loop https://codex.www.ads-software.com/The_Loop I understand that I can’t query $wp_query twicw. So on the 2nd one I used:

    <?php $my_query = new WP_Query category_name=oranges'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    list all posts with orange category
    <?php endwhile; ?>

    But this had the same problem! I also tried <?php wp_reset_query(); ?> after the second loop and before the comments but still no joy! If anyone can out me on the right track that would be great!!!!

    appreciated
    Matt

Viewing 2 replies - 1 through 2 (of 2 total)
  • You might have a look at this method – It’s a little more involved, but I’ve had better luck with it in the past when I’m trying to do any sort of complex post query:

    https://codex.www.ads-software.com/Displaying_Posts_Using_a_Custom_Select_Query

    Thread Starter mattyk

    (@mattyk)

    Thanks peterebutler for that. Looks a bit too complicated for my PHP understanding butits good to have another option if other things fail. I thought i’d fixed it a moment ago.

    I changed the $post->comment_status to = open at the end of the 2nd loop. This gave me control over the comment form but when I tested it went to “wp-comments-post.php” in the root and said that “comments were closed”. It must still be taking the status from the last post of the main loop.

    Does anyone else have any suggestions?

    Many thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘loop within a page allowing for comments’ is closed to new replies.