IPB

Welcome Guest ( Log In | Register )

Movable Type

We're moving to movabletype.org!

At long last, we're moving to forums powered by, well, Movable Type itself. You'll want to bookmark http://forums.movabletype.org/ for future reference, and in the meantime you can view these old forums as a read-only archive of past posts. Thanks for being part of the community!

 
Reply to this topicStart new topic
> Sorting MTCategories, MTCategories sort_by=???
craig1972
post Jan 14 2004, 06:30 PM
Post #1





Group: Members
Posts: 156
Joined: 15-February 03
Member No.: 7,968



In my index template, I want to display all categories, and then all entries underneath.

Here is what I have:

CODE
<MTCategories sort_by="MTCategoryID">
....
</MTCategories>


The "sort_by" doesn't seem to be working! I have tried "category_id", "id" etc.

Help! How should I sort the listing of categories which is currently by default based on the category title? I want it to be by category ID.

P.S. Manual didn't mention any specific "sort_by" for the MTCategories. Is this possible?

Thanks!
Go to the top of the page
 
+Quote Post
cutterchgo
post Jan 14 2004, 08:02 PM
Post #2





Group: Members
Posts: 19
Joined: 28-October 03
From: Chicago, IL
Member No.: 17,108



I've been using a neat trick for sorting categories that I found on here somewhere. It requires the regex plugin.

Simply, add numbers to your category names. For example, if you have three categories named:

cat1
cat2
cat3

rename them to

1cat1
2cat2
3cat3

Now, they will appear in the order (1,2,3) but they have that ugly number in front of them. That's where the regex tip comes in:

First, you'll need to install the regex plugin from www.bradchoate.com.

Then, in your template, add the following:
CODE
<MTAddRegex name="RemoveSortNumber">s|^([\d\.]*\s*)||</MTAddRegex>

This sets up the expression to be applied to your MT tags.

Next, in every case where you wish to output the category name, use the following:

CODE
<$MTCategoryLabel regex="RemoveSortNumber"$>


Or some variant. Just be sure to include the "regex='RemoveSortNumber'" argument to apply the expression that removes the number from the beginning of your category. I am using this to control the sort of all of the pages in the site I am working on. It's a bit weird at first, but once you get it setup, it's a breeze to work with.[CODE]
Go to the top of the page
 
+Quote Post
craig1972
post Jan 15 2004, 05:20 AM
Post #3





Group: Members
Posts: 156
Joined: 15-February 03
Member No.: 7,968



Thanks, this is useful, but to be honest I have thought of this.

I was wondering if sorting (which is a BASIC feature!) is possible in a cleaner fashion?

Thanks!
Go to the top of the page
 
+Quote Post
cutterchgo
post Jan 15 2004, 10:08 AM
Post #4





Group: Members
Posts: 19
Joined: 28-October 03
From: Chicago, IL
Member No.: 17,108



I don't think so. When I was scouring for it it seems that categories are only sortable alphabetically. I couldn't find any plug-ins that added this ability outside of the solution I posted and a more complicated one using the lists plug-in to put the categories in a list and THEN sort them (My guess is that you'd have to use key value pairs to identify the position in this case and have the list plug-in sort the records by that value rather than name. It seemed more complicated so I didn't bother trying it.

Anyone else have any ideas? A simpler one definitely would make life a bit easier.
Go to the top of the page
 
+Quote Post
imabug
post Jan 15 2004, 10:26 AM
Post #5





Group: Members
Posts: 2,543
Joined: 16-October 03
Member No.: 16,767



QUOTE
The "sort_by" doesn't seem to be working! I have tried "category_id", "id" etc.


Probably a sign that sort_by isn't a valid attribute for MTCategories.

I don't see any sorting plugins off hand, but if your blog is SQL based, something that might help is the SQL plugin. set up your SQL query to sort the list the way you want. Don't know if you'd be able to nest a MTEntries block in it though.


--------------------
MT 4.2 MySQL5.0.51 Perl 5.10.0 PHP5.2.5 Apache2.2
[img]http://feeds.feedburner.com/Imablog.gif[/img]
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GS d-(+) s: a C++ UX++++V++S++L++ P+>+++ L+++ E+>++ W++ N++(+++) o? K? w !O !M V-- PS PE Y+ PGP++ t++ 5++ X++ R+ tv++ b++(+++) DI++++ D+ G++ e+++>++++ h--- r+++ y?
-----END GEEK CODE BLOCK-----
Go to the top of the page
 
+Quote Post
craig1972
post Jan 15 2004, 08:15 PM
Post #6





Group: Members
Posts: 156
Joined: 15-February 03
Member No.: 7,968



Thanks guys.

Cutter, thanks for that code, I have finally settled with it except that I am using brad's MTMacro instead of the regex, that easily wins my "Favorite Plugin" awards hands-down.

I have one additional question. So my categories now look like they should:

CODE
 CATEGORY 1:

 - Entry 1: This is good
 - Entry 2: This is super

 CATEGORY 2:

 - Entry 1: That is good
 - Entry 2: That is super
 - Entry 3: That is super cool


Now, I want to have the same sort of style when a user searches through my blog. E.g., if the search is for "super", I want to show the results as follows:

CODE
 CATEGORY 1:

 - Entry 2: This is super

 CATEGORY 2:

 - Entry 2: That is super
 - Entry 3: That is super cool



But I am not sure what I should include in the search template for this to work! The "MTSearchResults" tag doesn't seem to have any ArchiveList tag at all!

Any ideas? Thanks!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 11.25.09 - 12:13 AM