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.
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:
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.
post__in
will preserve the order of the values you give it.Assuming that “3,5,8,4” are post IDs, something like the following should work:
Of course, you will need to add other parameters that you might want.
Note: It is
cat
notcategory
, but it doesn’t matter sincepost__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.