tags:

views:

277

answers:

1

I am using the following code to try and display posts from only a certain category horizontally in three rows. I have the horizontal display issue figured out (using css) but with the following code it displays all posts and not posts from specific category.

<?php query_posts('showposts=5'); ?>
<?php query_posts('cat=7'); ?>
<?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>

<?php the_title(); ?>
<?php the_content(); ?>

<?php $count1++; } ?>
<?php endforeach; ?>

Any help would be greatly appreciated.

A: 

You're misunderstanding some concepts in query_posts and get_posts.

query_posts is to be used inside the loop. get_pages isn't. If you want to use query_posts, you don't need to create the get_pages call. Use query_posts or get_pages to accomplish what you're trying to do.

You need to combine your category parameters in query_posts.

<?php 
query_posts('showposts=5&cat=7');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
 ..
endwhile; else:
 ..
endif;

//Reset Query
wp_reset_query();
?>

If you want to do the same logic but without The Loop, just call

$posts = get_posts('numberposts=5&offset=0&category=7').

Read the links I provided. They have all information you need to understand how to do what you need.

GmonC