Build Your Own Business Website header image

Community News Case Study Part 10 – Create Category Display Order

Difficulty Level -

Filed Under Topics - , , ,

Listed Under Lesson Subjects - ,

Applies to - ,

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

This is the tenth in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this case study we are creating a community news site. This video explains how to add a category display order. Ordinarily categories are displayed by category id or alphabetically. We use the My Category Order plugin to order the categories and then change our category display loop to use that order.

Video Transcript

Okay so back to the… I think at this point, the 10th and final part of our Community News Case Study is going to be how to organize these categories by something other than alphabetical order, right? Right now, they’re in alphabetical order so you’ve got businesses, churches, neighborhoods, schools, weekend events. And let’s say you wanted to do something different than that.

Well what we need to do is we need to use a plugin in order to accomplish that. So I’m going to go back to my Dashboard and I’m going to come down to Plugins… let’s see… Plugins, Add New, and we’re going to search for My Category Order. Search for that plugin and it’s this plugin right here. You can see that I actually have it installed already so I’m not going to go through the process of doing that but My Category Order version 3.01 at this point is the right one to use.

And then if we go down to… we go back to Plugins and oh, My Category Order is even activated so now, we can look at My Category Order which comes down here under Categories and Post Tags. And right now, it’s happening alphabetically. I’m suggesting that what we do is let’s do weekend events at the top and churches in the middle and schools below churches. So here’s the order I’m proposing. It’s not alphabetical at all and you can drag and drop these things right, to get to where you want them to go. So if we click order to those categories, now they’re ordered.

So then what we do is we come back over to our custom functions php file and in our category let’s see… so, if you look at recent categorized Edmonds post, this was that function that we created. We are excluding category1 and I’ve added this order by order. Now ordinarily, order by only exists for order by post id, order by date, order by name. There are a couple of other order by’s as well. Interestingly enough, for categories, not order by meta and that prevents us from using some kind of category meta for organizing this. However, having said that, because of this plugin, this plugin adds the ability to order by order rather than ordering by any of the other normal standards.

And so that’s what we’ve done here. If you looked down here, you can see that… oh let’s see… args = array, exclude 1 order by order… and this is what it used to be. It used to be args = array exclude category 1 which was uncategorized. I will, in a moment, I’m going to show you what this looks like on the live site. In fact, I’m just going to do that right now.

So here we are, we’ve ordered this stuff. If we go the Community News Case Studies and if we look at the Edmonds set, you can see that weekend events is first, church is the 2nd, schools is 3rd, neighborhoods is 4th and business is last. Whereas if we go over to Seattle where we haven’t used that order by, it’s still in the alphabetical order: business, churches, neighborhoods, schools, and weekend events. So what we do then is in our custom functions php file here, we come down to this… remember, what we’ve done here is we have used the command get categories and we’ve placed that array of categories in this variable called categories and we’ve defined that array as…right now, it’s getting every category except for one.

Now, what we’re going to do is we’re going to get every category except for one and we are going to order it. So let’s… and then we’ll just go order by… and then come over, equals greater than and then order. Let’s just make sure that order by is order by underscore… no, it’s not. It’s nothing at all there so we get that out. If I don’t remember that stuff… and so, now we’ve got args = array exclude 1 order by order. And now it’s going to get all the categories except for category 1 and it’s going to organize them by their order in this thing called categories… in this array called categories. And then in this for each loop, it’ll take each category in turn, in the order that it was put in this and do the display on the post.

So we’ll go ahead and save that. We’ll open Filezilla and where is that community byob tutorial? WP content themes, thesis_18, custom, and custom functions php… upload that. Come back over here, we’re on Seattle now. Let’s just refresh Seattle and this should go on the right order. There we go. Weekend events, churches, schools, neighborhoods, and businesses.

So for the time being, that’s the end of Part 10 of this Community News Case Study.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 comments… add one

Leave a Comment