Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I made a custom page with a template that is just a loop with custom query string for a list of posts from a specific category but when I view the page it only shows one post with the title being the title of the page. I don't understand why it doesn't return the loop of posts. What am I doing wrong? Heres the page template.

<?php
  /*
  Template Name: music videos
  */
?>
 <div class="panes-feed">
   <ul>
    <?php
     global $query_string;
     query_posts($query_string .'&posts_per_page=10&cat=3&orderby=asc'); ?> 
    <?php $i=0; while (have_posts()) : the_post(); $i++; ?>
      <li>
      <a style="display:block;height:100%" href="<?php the_permalink() ?>"  rel="bookmark" title="<?php _e( 'Permanent Link to', 'buddypress' ) ?> <?php the_title_attribute(); ?>">
           <?php
              foreach((get_the_category()) as $category) {
              echo "<div id='$category->slug' style='margin-right:4px;position:absolute;right:0;display:block' title='$category->cat_name'></div>";
             }
           ?>
        <span class="video-thumb">
          <span class="video-clip">
            <span class="video-clip-inner">
               <?php $video_code = tube_getcustomfield('video_code',get_the_ID()); if($video_code) { ?>
                <img src="<?php $thumb = get_youtube_screen_link( $video_code, 'default' ) ?>" width="120" height="90" />
               <?php } else { ?>
                <?php echo_first_image ($post->ID); ?>
               <?php } ?>
               <span class="vertical-align"></span>
               </span></span></span>
                <div style="display:inline-block;width:225px">
                <h3 style="color:#e2e2e2"><?php the_title(); ?></h3> 
                <p><?php echo time_ago(); ?><?php _e( ' in', 'buddypress' ) ?> <span><?php $category = get_the_category(); echo $category[0]->cat_name; ?></span> </p>
                <?php if(function_exists('the_views')) {  ?><p style="font-size:11px;margin-bottom:0px"><?php the_views(); ?> </p><?php } ?>
                </div>

     </a>
  </li>                                             
<?php if($i%1==0) : ?><div class="clear"></div><?php endif; ?>
<?php endwhile; wp_reset_query(); ?>
</ul>
</div>
share|improve this question
    
where is the $query_string defined? –  Sisir Mar 7 '12 at 9:08
    
line 8 right? That loop works when I place it directly on my index page. For some reason on a custom page it doesn't. –  Pollux Khafra Mar 7 '12 at 9:21
    
Add global $query_string; on top of your template (after the comment). –  kaiser Mar 7 '12 at 9:22
    
That didn't change anything which is weird because the wordpress codex says it should. –  Pollux Khafra Mar 7 '12 at 9:30
add comment

1 Answer

up vote 1 down vote accepted

You should remove $query_string from the template. the Quesry string contains params specific to your page...

your loop should look like this:

<?php
query_posts("posts_per_page=10&cat=3&orderby=asc&paged=".get_query_var('paged'));
if (have_posts()):
    while(have_posts()):
       the_post();
       <!-- your custom data here -->
       the_title();
       the_content();
    endwhile;
endif;
?>
share|improve this answer
    
For some reason thats only returning one post for the category. –  Pollux Khafra Mar 7 '12 at 9:43
    
Odd it only returns one post on the page but when it call it to the homepage with ajax it returns all the posts. Im gonna call that a win since that's all I needed it for. –  Pollux Khafra Mar 7 '12 at 9:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.