Nodes displayed when a category is viewed are sorted by 'promoted' status and then by reverse chronology by date posted. This sort order is hard-coded as into the function taxonomy_select_nodes() in taxonomy.module as follows: ORDER BY n.sticky DESC, n.created DESC. Thus, there is no way for site administrators to choose a different way of presenting content in taxonomies.

Enabling choice in presentation order is partially addressed by the proposed node weighting patch, http://drupal.org/node/5738. Yet it would also be useful to have other options--e.g., alphabetical listing by title.

Some initial ideas on enabling customized sort order are presented in the posts Sort order for taxonomy pages and Getting Drupal node listings to sort by node title ascending.

Requests for custom sort order functionality include:

Drawing on jibbajabba's "Overriding Drupal's sort order on node display" proposals at http://urlgreyhot.com/drupal/node/view/1432, the attached patch is a first take on how sort order might be implemented. It introduces two new settings to the taxonomy module (field to sort by and sort direction). When these are set, nodes viewed by taxonomy term are sorted accordingly. Options are:

  • alphabetical by title, ascending
  • alphabetical by title, descending
  • chronological by post date
  • reverse chronological by post date
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

erikhopp’s picture

personally, i would like to see options like this for content type. but hopefully both could be available.

moshe weitzman’s picture

this patch seems undrupalish at the moment. i suggest alternate sortings be dispayed by via contrib modules. those contrib modules would likely reuse everything from taxonomy.module except for a custom taxonoy_select_nodes()

nedjo’s picture

Thanks for the comments. Could you specify what makes it "undrupalish"? This might help make it "more drupalish".

I don't quite see the alternative you're suggesting. It's the taxonomy module that controls display in taxonomies e.g., when viewing a page taxonomy/term/3. How could the term display be modified via a module?

Besides the one I sketched in (which I'm by no means attached to), other approaches to the problem of specifying a sort order within a taxonomy term might be:

  • passing in parameters via the url (one for field, one for sort direction)
  • adding fields to vocabulary or term_data table, indicating sort order for a specific vocabulary or term

Would either of these be preferable? If not, are there alternate suggestions for answering this need?

moshe weitzman’s picture

one way to implement different sort orders, i suggest you write a new module which will handle new urls. if you call your module 'megasort' then you can make up your own urls like

megasort/term/3

then, you control sort order with settings in admin pages. or you can make more complex urls like

megasort/created/asc/term/3

the second 2 arguments above define a sort order. the only issue with this is if you want these to *replace* the regular term urls that are shown in nodes. in order for that to happen, you can probably do some str_replace() inside your theme.

the key function to write is megasort_select_nodes(). ten you will call taxonomy_render_nodes() just like taxonomy.module does.

nedjo’s picture

Thanks for the explanation. While the custom module approach would certainly be feasible, I don't generally like the approach of replacing a core module just to get one small bit of functionality (unless that functionality is obscure enough that few will want or need it). The main problem with this approach is that it leads to a plethora of ways of viewing content, each incompatible with the others (or requires hacking of themes to override the core).

As shown by the many requests, many users wish or expect to be able to set a sort order for nodes in categories. This basic functionality should be there in the core.

A sort order is already in the taxonomy module. The point is only to allow choice, rather than having it hard-coded.

Suggestions on how to improve on the approach I sketched in?

anj’s picture

Using a custom 'megasort' module can be made to work, but this will require patching part of the node display. Currently, when you are viewing a node, category links are automatically generated which point to the taxonomy module: $taxonomy = module_invoke('taxonomy', 'form_all') in node.module. (There may be other implicit dependancies upon the taxonomy module like this, e.g. the theme hacking mentioned above, but this is the main one that springs to mind at the moment). This would have to be changed to allow the admin user to specify which module should handle the classification. This approach could rather messy, and as a number of modules now rely on taxonomy to sort and display things (weblink, image), I think the simplest solution is to add this functionality to the taxonomy module.

I realise that the 'Drupalish' approach is to minimise the amout of switchable code (to avoid code bloat) and use custom modules for tweaking the display, but I think the things we are considering here are too close to the Drupal core for that approach to work. This is all IMHO of course, as I'm not as familiar with the Drupal core as I would like to be, but I cannot think of an neat way of using the module system to add this type of functionality to such a fundamental part of Drupal as the taxonomy.

Cheers,
Andy J.

anj’s picture

Scratch that comment about the image galleries - the version I just downloaded has reinstated it's galleries. Perhaps the same will happen to the weblinks module.

I think my own confusion here is perhaps rather common, and it might help to explain it here. The fact that one can browse the site content via the taxonomy module means that when one installs a module that uses the categories to arrange it's contents, you can end up with two different ways to browse the content. For example, images can be examined via the taxonomy module or via the image module's galleries. This would not be much of a problem if they were completely separate interfaces, but the way nodes are presented means that the user will probably end up switching from the gallery view to the taxonomy view (via the post metadata tags/breadcrumbs in the node view), when they were expecting to stay in the gallery view.

I end up thinking that I must be doing something wrong, but I cannot find out what. How am I supposed to view my galleries? Is the image module doing something wrong? Should it be overriding/ignoring the node-view so that the links on it's pages always point to the image module? In that case, *no* module should *ever* use the plain node view for categorised data. But the, if the taxonomy view is not meant to allow you to control how the terms are viewed, why does the taxonomy module support viewing the nodes at all? Or should I stick to the taxonomy view and hack it to make that work?

I couldn't find anything about this in the documentation to clear this issue up. I will happily add a page to the handbook about it if someone explains the idea to me.

Cheers,
Andy J.

Steven’s picture

A related patch was committed. That patch only covered the API taxonomy_select_nodes() and added a $order parameter.

It is up to a contributed to take advantage of this with an advanced URL scheme. Later, it can be moved into core if it is good enough.

bermin’s picture

Has anyone updated this patch for 4.6.2? It appears that some of the variable names have changed and I don't have the know how to make the changes.

Or perhaps someone has used this patch (http://drupal.org/node/20963) to give the same functionality described in this thread?

tostinni’s picture

Well, there hadn't had so much changes in the names, so it should not be so difficult to apply it.
You can also use mine, but basically it's the same one. It just depend then where would you use it to define the way to call taxonomy_select_nodes()

moshe weitzman’s picture

an alternative is to use weight.module in contrib. it uses the sticky column to store weights, and drupal just naturally uses it.

likoma’s picture

Is that patched module (file) available anywhere for download? I'm using 4.6.2 and I think this patch is for the CVS version, maybe that's been my problem with trying to patch it (http://drupal.org/node/14231#comment-50081). In any case, I'd just plain love to get one node (Events) to sort ASC while the other nodes sort DESC. However, at this point, I'd be happy to just make the whole site sort ASC and deal with it later. Thanks. -- Bradley

tostinni’s picture

Remember that this kind of patch is only a way to allow modules using taxonomy to get a way to order nodes. In your case you have to ask to event maintainers a way to allow events to be ordered the way you want.

A similar version of this patch has been commited to CVS, the Drupal 4.7 will be available current september, so I think it worth the wait.

robertgarrigos’s picture

The problem with the weight.module is that doesn't sort alphabetically.

Somebody pointed this thread to me because I was asking some feedback on a small sorting.module I wrote for one of my sites. You can find it here: http://drupal.org/node/37899 and give it a try. It is working with 4.6.3, right now. Please, give some feedback if you try it!

robertgarrigos’s picture

I realize this patch does almost the same mine does :-) I added some more variables to have also promoted nodes ordered by other fields. And other options can be added, like sorting 'product' nodes and flexinode nodes.

nedjo’s picture

Assigned: Unassigned » nedjo
Status: Closed (duplicate) » Active
FileSize
1.61 KB

We now have a method available for taxonomy-based listings to be sorted (issue: http://drupal.org/node/20963), but there is still now way for this to be used by the taxonomy module's default listings e.g. taxonomy/term/21. This remains a frequently requested feature (see e.g. http://drupal.org/node/48164).

There are many ways this could be done--additional fields or system variables, taxonomy admin pages or interactive user elements, etc. What we seem to need is not a developed solution in taxonomy.module, but a way for other modules to specify sort orders.

So here's a new proposal. We introduce a hook, 'taxonomy_sort_order', and pass it the info on the term(s) being viewed. Then a module can use whatever approach it likes to determine sort order. E.g., set an overall default, a default per vocabulary, plus optional custom orders per term. (Since we can only specify one sort order, we would need to use only one module-returned value.)

Setting this to active rather than patch until after 4.7.

moshe weitzman’s picture

I think Views module now gives you these options out of the box.

marcp’s picture

I'd sure like to see this too. As it is now, I'll be copy-and-pasting taxonomy_term_page() just so I can pass an ORDER string to taxonomy_select_nodes(). If the hook seems too big of a change, how about adding an optional $order to the end of the footprint the way it is in taxonomy_select_nodes()?

Views seems like a heavy price to pay for this little added bit of useful functionality that people are expecting to find in core.

lafingguy’s picture

I've been looking at the views builder and it seems to only work on the "standard" node fields.
I would also like to see this work for events and sort nodes by the start date/end date (per the post that started this thread).
B-)

faunapolis’s picture

Version: x.y.z » 5.5

Suscribing, very interested in this option as I need to sort a list of nodes from a taxonomy term (without using views).

marcp’s picture

@faunapolis - you may want to take a look at Nodeorder if you haven't already. It works fine for ordering nodes in single-level vocabularies. Please post issues with that project, if you try it, to the Nodeorder issue queue (and check out the current issues if you're having trouble).

yched’s picture

Nodequeue also brings this feature, and is an extremely useful tool for lots of other reasons.

yched’s picture

Status: Active » Closed (won't fix)

...which makes this a 'won't fix' in core

SamRose’s picture

Status: Closed (won't fix) » Active

Hi,

I think that, for taxonomy, it seems kind of weird to me that all of this time, from the beginning of this issue 2 years ago, till now, that patches have not been worked into core to at least allow taxonomy nodes to appear in alternate orders besides stickiness or date of creation in taxonomy. In particular, I know a lot of people would like to see the option for alphabetical sort order be an *automatic* option. I think Node Order and Nodeque are ok options, but require a lot of manual labor on the part of the user, that a few simple lines of code could alleviate, in creating an option for sort order in taxonomy default listings

I am not active in the development of Drupal, so I lack a literacy to understand over time what happened with the original patch submitted back in 2004 at the beginning of this issue.

Maybe I am missing something here...?

moshe weitzman’s picture

Status: Active » Closed (won't fix)

you argument for changing status reads to me like "this is useful and shouldn't be hard". thats not compelling for all the reasons listed here.

SamRose’s picture

maybe I just need to look more closely at Nodeque....

boreg’s picture

My solution is theme based and works fine for Drupal 6.x:
http://drupal.org/node/10820#comment-1452074