Changing sort order in template.php

newswatch - June 3, 2007 - 08:56

I want to change the sort order of ALL nodes to alphabetical (i.e. by title). Doing anything with teh taxonomy_select_nodes doesn't make sense since that is limited to taxonomy. I want the order to be alphabetical throughout the site. Can't find appropriate function to do that?

I want o make the changes in the template.php file itself so that I need not hack into the core. Is this possible?

I was thinking

dan33 - June 3, 2007 - 09:38

I was thinking hook_db_rewrite_sql, but it appears it's limited to join, where, and distinct. I'd be kind of curious as to the answer of this as well.

Yeah. And it doesn't make

newswatch - June 6, 2007 - 06:29

Yeah. And it doesn't make sense to create 50,000 Views if a single line (or maybe 10 lines) in template.php can do the needful.

I tried to introduce this in

newswatch - June 6, 2007 - 07:12

I tried to introduce this in the template

function node_page_default() {
    $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.title DESC'), variable_get('default_nodes_main', 10));
}

Gives error:

Cannot redeclare node_page_default() (previously declared in /home/twatch/public_html/modules/node/node.module:2374) in /home/twatch/public_html/themes/tourismwatch/template.php on line 143

Changed node.module

newswatch - June 6, 2007 - 10:04

I got tired of trying to tinker around with template.php. So I changed line 2374 of node.module to

  $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.title FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.title ASC'), variable_get('default_nodes_main', 10));

Of course, it works.

I would have liked to do the same in template.php.

 
 

Drupal is a registered trademark of Dries Buytaert.