Build Your Own Business Website header image

Community Library Website Case Study – Part 55 Add Sort Order to Custom Taxonomy

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 55th in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this lesson we add a sort order to our custom taxonomies by means of a modified version of the My Category Order plugin. Once we’ve modified the plugin, we add that sort to our code.

Video Transcript

Rick: Okay so then the next thing we’re going to do is we’re going to sort these taxonomies and Pam, I’m going to unmute your microphone now for a moment. And what you want to do as I understand it is you don’t want…right now, the taxonomies are being organized alphabetically, right? So Bible and Reference comes first and then Biographies comes next and DVDs comes next and so on and so forth.

Pam: Right.

Rick: And so, what you want to do is pick a specific order for those things.

Pam: Yes, that’s correct.

Rick: Okay so think about that order for a moment while I show you how to do it, okay?

Okay. I’ll turn your microphone back on and we’ll talk about the order. But first, I’m going to just do this thing here. So we’re going to install a plugin. Let’s see, it’s called My Category Order and then we’re going to replace a bunch of its functions so that it will work with taxonomies. So let’s select Add New and say My Category Order and we’ll install it. Activate the plugin and now, if we come over here to My Category Order, we don’t have any categories to organize so you can’t see them here. And this only orders categories at the moment so it’s not pretty exciting looking but once we swap the code out, it’s going to be great.

So the next thing to do then is to come back over to our Filezilla and I am going to download My Category Order to my local machine here. And then I’m going to open the file…oh no, not open project. Pardon me, open file and then tutorial sites and the library, content plugins, my category order and then we’re going to take mycategoryorder.php. We’re going to open that up and then I’m going to come over here to my site and do the same thing. Plugins and My Category Order and we’re going to open up mycategoryorder.php and we’re going to take all of the content here. Now, what you’ll be doing is you’ll be taking this out of the forum. We’re going to take 100% of this content and we are going to replace 100% of the content that comes with the plugin with that. Save the document, upload it, My Category upload. And now, through the goodwill of others, if we refresh this screen, now you can change your taxonomy. Instead of categories, now what we’re going to do is change locations. So we change the taxonomy and now what you can do is you can drag and drop these things around. So Pam, yes I am going to post this code. Pam, I’m going to turn your microphone back on. So Pam, how do you want this thing organized?

Pam: Oh well, let’s see. Let’s put Audio just arbitrarily of course, just for the moment, let’s put Audiobooks at the top and is there a Children’s Audio? Oh you don’t have Children’s Audiobooks, okay.

Rick: No, I don’t.

Pam: Well, let’s move DVDs up next and then Fiction down here at the bottom. Then Non-Fiction and…oh I guess, in any order, the rest of the Adult Categories. I’ve tinkered with mine so much that my categories are different than yours and that doesn’t matter of course. And let’s not put… well, Storage wouldn’t be new. Anyway, Storage can just…

Rick: Yeah, just go down here at the bottom.

Pam: Yeah. We don’t have anything in Storage.

Rick: So now if we hit click to order categories…

Pam: That is wonderful.

Rick: I think we did it. Categories are updated successfully. Now, we need to change our code a little bit and the place we change our code… oh, pardon me. This is code that we can close. The place we change our code is up here when we get our location names, right? We have get terms location. What we’re going to do is we’re going to add a new argument to this. So in fact, what we’re going to do is we’re going to move this up for a second here and what we’re going to say is args. Let’s see, actually I think I’m going to make this location args. Okay and then up here, we’ll say location args equals array. And so, it’s going to be fields space space… come back to that. Do a little arrow and then so fields equals names and then comma, drop down, tab tabtabtab and then it’s going to be not fields but order by and equals arrow space. And then we say term order. Because what has happened here is that plugin created a field for all taxonomies called term order. And so now, we’ve said okay now what we want to do is order it by the term order. So now what we have to do is save that. So it’s a very small change to the code. We save that, let’s see… we got to go back to where we are. We upload that and we go to our site and let’s see… and we just go look at it. We go to custom catalog…maybe it’s not term order. Maybe I was mistaken. You know, I must have used the wrong syntax there. Term order, oh no… this is what I get wrong. There’s no space in there. Order by is what it is. Save… I think I’m going to get by tonight without failing at anything which is going to be just terrific. Okay, there we go. DVDs up at the top, now Fiction then Non-Fiction and yeah… lots of non-fictions there. Bible and Reference, so on and so forth. So we nailed it. You happy with that, Pam?

Pam: Yes, that looks great.

Rick: Did you get a new internet connection?

Pam: No, why?

Rick: You know, because whenever I talk to you, you know, there’s this weird sound in the background that sounds like somebody’s flushing the toilet although it’s obviously not. You know, I just assumed it was Clearwire and in fact, I have had that with other people when I’ve talked to them on Clearwire. But it hasn’t been there at all tonight. So I just assumed..

Pam: I changed my audio set up from default to specific for the brand headphone I’m using.

Rick: Well, that’s probably what it was then because it’s perfect now. I used to have to turn you off because I didn’t want to you know, have this sound in the background too much. That’s great. Okay well and is there anything you want to ask about any of those things?

Pam: No, that is great and that will fix the sorting problem I was having with those buttons. So it’s wonderful.

Rick: Perfect.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 comments… add one