SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict LittleFigment's Avatar
    Join Date
    Jan 2004
    Location
    Dublin, Ireland
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress posts loop help

    Hi guys,
    I am putting together a single page collecting together all the posts from a category:
    http://www.sheepstealers.ie/gaaquotes/

    If i move the page content code below the category content code it takes on the category ID and starts to display all the posts from the category instead of just the content for this page.

    How can I change the code of the first loop so that it only displays that pages content no matter where in the page i put it?

    Or even better, how can i split it up so i display the page content above the category content and display the comments below the category content.

    Hope that makes sense.
    Alan

    Code:
    <!--START OF CONTENT FROM PAGE ITSELF -->
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php comments_template(); ?>
    <?php endwhile; endif; ?>
    <!--END OF CONTENT FROM PAGE ITSELF -->
    
    <!--START OF CONTENT FROM CATEGORY -->
    <?php query_posts('cat=51'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div class="gaaquote">
    <div class="shadowtop"></div>
    <?php if ( function_exists('jr_post_image') ) { jr_post_image($id); } ?>
    <a href="<?php the_permalink()?>"><?php if ( has_post_thumbnail() ) {
        the_post_thumbnail( array(200,200) );
    } ?></a>
    <!--<?php the_excerpt(); ?> -->
    <div class="shadowbottom"></div>
    </div>
    
    <?php endwhile; endif; ?>
    <!--END OF CONTENT FROM CATEGORY -->
    Spoiltchild Design Consultancy - Design | Web | Motion
    Rudeball - Spot the Ball game engine for your site.
    Wedding Tickers Counting down to your wedding..

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Personally i prefer to use the WP_Query class over the query_posts() function as you get more control over the loop, see the following link for more information.

    http://codex.wordpress.org/Class_Reference/WP_Query

  3. #3
    SitePoint Addict LittleFigment's Avatar
    Join Date
    Jan 2004
    Location
    Dublin, Ireland
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant thanks Chris, i got this sorted with the new query.
    For anyone else looking in future:

    Code:
    <!--START OF THIS PAGE CONTENT -->
    <?php
    
    // The Query
    $the_query = new WP_Query('page_id=1580');
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	the_title();
    	the_content();
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    
    ?>
    
    <!--END OF THIS PAGE CONTENT -->
    
    <!--START OF THIS CATEGORY POSTS -->
    <?php
    
    // The Query
    $the_query = new WP_Query( 'cat=51' );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    
    	echo '<div class="gaaquote">';
    	echo '<div class="shadowtop"></div>';
    	echo '<a href="'; 
    	the_permalink(); 
    	echo '">';
    	the_post_thumbnail( array(200,200) );
    	echo '</a>';
    	echo '<div class="shadowbottom"></div>';
    	echo '</div>';
    	
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    
    ?>
    <!--END OF THIS CATEGORY POSTS -->
    
    <div class="clearall"></div>
    
    <!--START OF THIS PAGE COMMENTS -->
    <?php
    
    // The Query
    $the_query = new WP_Query('page_id=1580');
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	comments_template(); 
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    
    ?>
    
    <!--SEND OF THIS PAGE COMMENTS -->
    Spoiltchild Design Consultancy - Design | Web | Motion
    Rudeball - Spot the Ball game engine for your site.
    Wedding Tickers Counting down to your wedding..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •