Query Post not displaying correct category
-
I’m having trouble with the code below. It doesn’t seem to be displaying post from the specified category, instead it’s displaying all posts.
Thanks
<?php query_posts($query_string.'category=5&showposts=4'); $counter=0; while (have_posts()) : $counter++; switch($counter) { case 1: case 2: the_post(); ?> <ul class="post"> <li> <div class="news-post" id="news-<?php the_ID(); ?>"> <div class="news-thumb news-main"><!-- Thumbnail Wrapper --> <h5 class="news-title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h5> <?php $image = get_post_meta($post->ID, 'thumbnail', true); ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php echo $image; ?>" alt="" /></a> <div class="post-date"><!-- Date --> <h2 class="date"><?php the_time('m/j') ?></h2> </div> <!-- /Date --> </div><!-- /Thumbnail Wrapper --> </div><!-- /Post ID --> </li> </ul> <?php break; case 3: $postslist = get_posts('category=7&showposts=1'); foreach ($postslist as $adpost) { setup_postdata($adpost); ?> <li> <div class="ad-post" id="ad-<?php the_ID(); ?>"> <div class="ad-thumb ad-main"><!-- Thumbnail Wrapper --> <h5 class="ad-title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h5> <?php $image = get_post_meta($post->ID, 'thumbnail', true); ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php echo $image; ?>" alt="" /></a> <div class="post-date"><!-- Date --> <h2 class="date">[Sponsored]</h2> </div> <!-- /Date --> </div><!-- /Thumbnail Wrapper --> </div><!-- /Ad ID --> </li> <?php } // end foreach // important: no break statement here case 4: the_post(); ?> <ul class="post"> <li> <div class="news-post" id="news-<?php the_ID(); ?>"> <div class="news-thumb news-main"><!-- Thumbnail Wrapper --> <h5 class="news-title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h5> <?php $image = get_post_meta($post->ID, 'thumbnail', true); ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php echo $image; ?>" alt="" /></a> <div class="post-date"><!-- Date --> <h2 class="date"><?php the_time('m/j') ?></h2> </div> <!-- /Date --> </div><!-- /Thumbnail Wrapper --> </div><!-- /Post ID --> </li> </ul> <?php break; } // end switch-case endwhile; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Query Post not displaying correct category’ is closed to new replies.