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.

  Template Name: music videos
 <div class="panes-feed">
     global $query_string;
     query_posts($query_string .'&posts_per_page=10&cat=3&orderby=asc'); ?> 
    <?php $i=0; while (have_posts()) : the_post(); $i++; ?>
      <a style="display:block;height:100%" href="<?php the_permalink() ?>"  rel="bookmark" title="<?php _e( 'Permanent Link to', 'buddypress' ) ?> <?php the_title_attribute(); ?>">
              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>
                <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 } ?>

<?php if($i%1==0) : ?><div class="clear"></div><?php endif; ?>
<?php endwhile; wp_reset_query(); ?>
  • 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

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

your loop should look like this:

if (have_posts()):
       <!-- your custom data here -->
| 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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