4

Is it possible to alphabetize the taxonomy page without using views?

for example:

THE TERM'S NAME
- A node
- B node
- C node
- D node

Thanks.

CLARIFICATION: I know I can reset the terms themselves to alphabetical, but that does not reset how the node teasers on the taxonomy term page are displayed (these remain in the order they where created). Resetting the display of teasers is what I am trying to achieve.

5

The taxonomy module uses the taxonomy_term_page function to build the page that list the nodes attached to a term. But the function that really do the query is the taxonomy_select_nodes that is called by this previous function.

Remember: Never hack core

So you can implement a custom module and use the hook_menu_alter to rewrite the page callback for the taxonomy/term/%taxonomy_term path using a new function based on the taxonomy_term_page to call your custom taxonomy_select_nodes function that perform the changes you need to order the nodes that way.

You'll need to do something like this:

function mymodule_menu_alter(&$items) {
  // Rewrite the taxonmy term page callback
  $items['taxonomy/term/%taxonomy_term']['page callback'] = 'mymodule_taxonomy_term_page';
}

After that you'll have to implement the mymodule_taxonomy_term_page function in order to be able to make the changes you need on the taxonomy_select_nodes() call:

function mymodule_taxonomy_term_page($term) {
  # code...

  if ($nids = mymodule_taxonomy_select_nodes($term->tid)) {
    # code...
  }
  # code...
}

Finally:

function mymodule_taxonomy_select_nodes() {
  # code...
}

You'll must JOIN the node table to build the query in the mymodule_taxonomy_select_nodes function because the taxonomy_index table doesn't have the node title.

Notice that will change the behavior of all taxonomy term pages.

For more info about how to create a custom module see http://drupal.org/node/361112.

  • Thanks for the in depth explanation, changing the callback does seem to make the most sense. I just wonder why this functionality isn't already built in? – RedRaven Jan 16 '13 at 14:36
  • I'm not sure, why you are not willing to use views. Is there any trouble using it. – GIRI Oct 12 '14 at 17:39
  • @GIRI I guess the question is more of a type to discover possibilities, as I found myself wondering, rather than to indeed avoid Views. – Wtower Jan 23 '15 at 15:17
  • If you use views or taxonomy display, you won't be able to use the taxonomy-term--VOCAB.tpl.php file to override. That is the problem I have right now. So I need to be able to sort without using views. – coderama May 25 '15 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.