views:

204

answers:

3

I wanted to re-arrange my recent post in wordpress so they go Ascending/Descending.

Here is my code:

    <ul>
<?php query_posts('cat=3,4,5&posts_per_page=5&order=ASC'); foreach ($post as $post)  ?>
<li>
<span class="date"><?php the_time('M j') ?></span>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>

</ul>

Each post is pulled from different categories. View site here

+1  A: 

try using "orderby" as well ...

see: http://codex.wordpress.org/Template_Tags/get_posts

farinspace
updated my post but no luck not working
kwek-kwek
+1  A: 

Why don't you use the standard query_posts?

<?php

//The Query
query_posts('cat=3,4,5&posts_per_page=5&order=ASC');

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
 ..
endwhile; else:
 ..
endif;


?>

This code should work, if there's another reason that you're using get_posts over query_posts your problem is likely to be your argument list - from what I can see you will need to change

get_posts('cat=3,4,5,numberposts=5&order=DESC&orderby=date')

to

get_posts('cat=3,4,5&numberposts=5&order=DESC&orderby=date')

as &'s are used to separate parameters.

Thomas McDonald
updated my post.. no luck not working.. I am not really good in PHP nor Wordpress. So i don't know if my syntax are correct.
kwek-kwek
@kwek-kwek: what does your current code produce?
Banjer
@banjer I included the demo in my post.
kwek-kwek
You need to add `orderby=date` to the query_posts parameter
adam
A: 

I would put categories 3,4,5 under a parent category. Then you could just pull in the single category (the parent category). For example, if you're new parent category is 17, you would do:

<?php query_posts('cat=17&numberposts=5&order=DESC&orderby=date'); foreach ($post as $post)  ?>

This will display posts in category 17 and any of category 17's children. Then sorting should happen as you'd expect it to.

Banjer
yes but then if I do that my "Blog Categories" would also display the Parent Category instead of just the the categories inside of it.
kwek-kwek