6

I've got this category setup that includes several posts. By design it's not a blog, but a staff listing. Currently all of the staff members have their own posts with the category. I'd like to be able to sort the order they are displayed in in their parent category.

How do I go about doing this in the most user friendly manner? My client may want to change this sorting order in the future, especially when staff members leave or new ones get hired.

Any and all help will be greatly appreciated.

http://gointrigue.com/beta/faculty/

To expand on this: In the link I've provided you'll be taken to a category page I made called /faculty/. In this category page I have several posts listed. Wordpress automatically lists them in the order they were created. With the most recently created post being listed first.

I want to list them in my own custom order. How do I do this?

2 Answers 2

8

Now that I have a better understanding of the issue, I would recommend using custom fields to sort your posts. You can have a custom field (e.g., "order") and use it to indicate the order of your posts. You then need to use a custom query to order these posts when they are displayed. You can use a custom query like the following:

$args = array(
    'meta_key' => 'order',
    'orderby' => 'meta_value',
    'order' => 'ASC'
);

$custom_query = new WP_Query();
$custom_query->query($args);

if($custom_query->have_posts())
{
    while($custom_query->have_posts())
    {
        $custom_query->the_post();

        // Do the loop stuff
    }
}

Please see the WP_Query class page for more information about all of the arguments that you can use to create custom queries.

7
  • Thanks! I found a plugin that would almost have worked, but it's not FULLY custom. Just came with a bunch of predefined orders. But it hasn't been updated anyway. QUESTION: in which files would I add my code for a new custom field. And in which file would I place the code for the custom query?
    – jkupczak
    Commented Aug 23, 2011 at 12:38
  • No new code is needed for the custom fields. Those are automatically part of your write screen. It the custom fields are not displayed by default, look at the "Screen Options" link in the upper right hand corner of the write screen to turn the custom fields on. You would use the code that I provided somewhere in the theme files. Take a look at the template hierarchy to get started: codex.wordpress.org/Template_Hierarchy
    – tollmanz
    Commented Aug 23, 2011 at 17:44
  • After some trial and error I got this to work! Only one problem. It doesn't sort correctly if I order posts with single and double digits, like: "8, 9, 10". Posts 1 and 10 end up being right next to each unless I type 1 as "01". Is there a way in the code to append a 0 to all single digit entries so that my client won't have to?
    – jkupczak
    Commented Aug 24, 2011 at 1:41
  • I am having one problem with the code above unfortunately. It seems it stops looping after it displays 10 posts. I thought maybe it was ignoring all numbers greater than 11. But it's really just stopping after displaying 10 total posts. Any ideas why this might be?
    – jkupczak
    Commented Aug 24, 2011 at 2:48
  • An easy way to fix the sorting issue is to start at 100, then 101, etc. It's only displaying 10 posts because it defaults to the number of posts set in Settings > Reading > "Blog pages show at most". You can either adjust that, or, to show all posts, add 'posts_per_page' => -1 to the args array.
    – tollmanz
    Commented Aug 24, 2011 at 5:59
0

I'm a little confused by your post as I think it could be asking a few different things. If you are asking how to order your categories by a custom order, please check out Custom Taxonomy Sort, a plugin that does just that. You can specify an order for each taxonomy term.

2
  • I installed the plugin you suggested and it doesn't seem to be what I'm looking for. There are only options here to add sorting order to categories. I want to sort the order that my posts appear in when you go to that category. In the link I provided in my original post you'll be taken to a category page. In this category page I have several posts listed. Wordpress automatically lists them in the order they were created. With the most recently created post being listed first. I want to list them in my own custom order. How do I do this?
    – jkupczak
    Commented Aug 23, 2011 at 2:17
  • I understand better now. I'll give you a new answer.
    – tollmanz
    Commented Aug 23, 2011 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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