Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display the all the posts that are inside a certain subcategory in a specific order that I decide (this is because the category contains a list of tutorials and I want to decide how to list them).

How can I do that?

Is there any plugin that I can use? I just want to be able to set the order when displaying that category.

Thanks.

share|improve this question
    
What order are you talking about? Different from the originally available or would you be fine with those? –  t f Apr 18 '13 at 13:44

2 Answers 2

You can use the get_posts() function and create a custom template file for that! This way you can take advantage of all the arguments that function makes use of. For example, to show all posts from a category that has id=47 you would do the following:

<ul>
<?php
global $post;
$args = array( 'numberposts' => 999, 'category' => 47, 'orderby' => 'post_date', 'order' => 'DESC',);
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

This will echo the titles of 999 posts (each title linking to the post itself) and it will format them as a list with the <ul>, <li> that we used. Of course you'll have to customize that to suit your use-case but this is a working principal.

I hope that helps!

Cheers, Ari.

share|improve this answer
    
Thanks for your reply. I've probably not explained fully my point. I need to order the blog posts with a specific order that I decide (and that I can change). For example, I want to display the posts in the order 3,5,8,4. How can I do that? –  nagar Apr 18 '13 at 14:17
    
You could add a custom field to those post. Let's say that this custom fiels is called "order_nr". In that case, you'd be able to format the arguments of the above query like this: $args = array( 'numberposts' => 999, 'category' => 47, 'meta_key' => 'order_nr', 'orderby' => 'meta_value', 'order' => 'ASC',); –  WPMU-DEV Ari Apr 18 '13 at 14:31
    
Are you aware of any plugin that allows to do that visually? Anyway, I'll check your suggestion. Thanks. –  nagar Apr 18 '13 at 18:14

post__in will preserve the order of the values you give it.

'post_in' - Preserve post ID order given in the post_in array (available with Version 3.5).

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Assuming that "3,5,8,4" are post IDs, something like the following should work:

$query = new WP_Query( 
  array ( 
    'post__in' => array(3,5,8,4)
  ) 
);

Of course, you will need to add other parameters that you might want.

Note: It is cat not category, but it doesn't matter since post__in will take care of everything anyway. That is, if you are picking the posts to display by ID, as it sounds like you want to do, you don't really need any other parameters.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.