开发者

How to Sort Wordpress Posts Horizontally, Calling by Category

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜