Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-06-22 16:08:35

sekhu
Member
Registered: 2005-05-12
Posts: 428
Website

Creating Sortable Archives

Thanks to Alex I saw this article on how to create sortable archives.

<del>However, frankly, I’m totally confused as to how to do this. I’ve created two sections called archive_posts and archive_links, I’ve then created two forms named the same and saved as article forms.

<del>Now, there’s mention of Javascript but I don’t see the code for that, or where to put if I do find it. Secondly, the output doesn’t seem right, as my results are here and here without links that work and without any articles actually displaying.

<del>I would be very grateful if someone would guide me through this and help me figure out how to achieve this effect as it’s really quite wonderful. Could it perhaps be converted to a plugin?

OK I’ve successfully got it working 50%+ and fortuately the 50% I need. What I need to do now is change the comments section to display the ratings instead, unfortunately I think this requires JS knowledge of which I have none. Can anyone help on getting this to work?

Thanks in advance

Last edited by sekhu (2006-06-22 23:19:03)

Offline

#2 2006-06-23 10:10:35

ricetxp
Member
From: London, UK
Registered: 2005-05-24
Posts: 89
Website

Re: Creating Sortable Archives

Hi sekhu
I like what you’ve done so far. I hope you’re going to add search functionality.

I’m also building a review site for wine. What rating system/plugin are you using?

Offline

#3 2006-06-23 12:55:09

sekhu
Member
Registered: 2005-05-12
Posts: 428
Website

Re: Creating Sortable Archives

I’m using a custom field to create the ratings I don’t really remember how I did it, as I got a lot of help from this forum. Here are the snippets of code I used:

Default form

<code>
<div id=“rating”><strong>Rating:</strong><br /><img src=”../images/<txp:custom_field name=“Rating” />.png” /></div></div>
</code>

In the custom field I added a field called Rating

I then uploaded images which correspond to the numbers, so 1 bull = 1.png and so on. When I use the custom field in the write page I simply use the number and the code takes care of the rest.

Hope that makes sense, as I dont’ remember all that much.

Dont’ suppose you can help with the JS query above?

Offline

#4 2006-06-23 15:17:58

ricetxp
Member
From: London, UK
Registered: 2005-05-24
Posts: 89
Website

Re: Creating Sortable Archives

Thanks for the info. Sorry, but js is not my thing. But then why use javascript at all? Surely you could use different urls and conditionals to sort the archive?

You’d have a menu form across the top with Date, Category, Title, Rating, etc. Hard code the links so that Date points to the section and the others point to a category. E.g. <a href="/archive_posts">Date</a><a href="/archive_posts/?c=category">Category</a> and so on.

You don’t have to assign articles to these categories.

For Ratings, you simply have a number 1 to 5 in the custom field.

Now you create the conditional to display the archive sorted according to url.
<code>
<txp:if_category>
<txp:output_form form=“archivesort” />
<txp: else />
<txp:article_custom form=“yourform” sortby=“Posted” limit=“9999” />
</txp:if_category>
</code>

Now the form called archivesort for the other conditionals:
<code>
<txp:if_category name=“category”>
<txp:article_custom form=“yourform” sortby=“Category1” limit=“9999” />
</txp:if_category>
<txp:if_category name=“title”>
<txp:article_custom form=“yourform” sortby=“Title” limit=“9999” />
</txp:if_category>
<txp:if_category name=“rating”>
<txp:article_custom form=“yourform” sortby=“Custom_#” limit=“9999” />
</txp:if_category>
</code> etc…

So when you click on rating, for example, the url should be ragingbulls.com/archive_posts/?c=rating and that will call a custom article list which will be sorted by rating.

Offline

#5 2006-06-23 22:09:05

sekhu
Member
Registered: 2005-05-12
Posts: 428
Website

Re: Creating Sortable Archives

it sounds good but it’s confused me :)

I’ll try and understand it and give it a go

thanks

Offline

#6 2006-06-24 11:42:53

ricetxp
Member
From: London, UK
Registered: 2005-05-24
Posts: 89
Website

Re: Creating Sortable Archives

Ok, I’ve had a look at the javascript (I know I said it’s not my thing, but I can read the stuff – just can’t write it). The script is trying to sort your data by date, alphabet or number. So the reason it can’t sort the ratings is that there is no number value, only images.

So, perhaps an easier solution to the last one I posted is to add a number next to the rating image. This is the same number which comes from your custom field called Rating. For example, 1 (followed by the image of 1.png) and so on. You can style it so that the number doesn’t appear.

Code might look something like this:
<code>
<div id=“rating”><strong>Rating:</strong><br /><span class=“rating-num”><txp:custom_field name=“Rating” /></span><img src=”../images/<txp:custom_field name=“Rating” />.png” /></div></div>
</code>

Add this to your css:
<code>
.rating-num {display:none}
</code>

Offline

#7 2006-06-24 13:16:52

sekhu
Member
Registered: 2005-05-12
Posts: 428
Website

Re: Creating Sortable Archives

thank you very much, that works perfectly :)

Cheers again

Offline

Board footer

Powered by FluxBB