Forums

Query Post not displaying correct category (3 posts)

  1. Samuel
    Member
    Posted 2 years ago #

    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;
    
    	?>
  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    When using query_posts in this way, the quoted portion of the argument must begin with an ampersand (&).

    http://codex.wordpress.org/Template_Tags/query_posts

    query_posts($query_string.'&category=5&showposts=4');

  3. Samuel
    Member
    Posted 2 years ago #

    Thanks for getting back to me. I did add an ampersand as suggested, however I'm still having the same problem. Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.