Book order by title isn't working out for me, since for some odd reason 10 comes after 1
In Example: My node titles are numbered from 1- (xx)

Title order should be like this:
1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10 . 11 . 12 . 13 . 14

But it's ordering like this:
1 . 10 . 11 . 12 . 13 . 14 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9

I am confused. I do not like how they are ordering, so I decided maybe ordering by date posted or n.id would solve the problem. So here I am asking for your help. I am using the Book-Navigation system under each child pages.

Ordering by weight solves the problem... but I have over 5k+ nodes, and it is not essential to order them manually.

Comments

N1L’s picture

Will it be possible to do this via views? How can I have navigation block with next and previous links? And how do I insert this block in the template?

Also if it's possible to do via views, how can I show it under the parent page with all the child pages links?

Thanks in advanced.

N1L’s picture

***bump

N1L’s picture

***bump^2

N1L’s picture

If I could somehow multiply the title by *1, then it would fix the order. But I don't know what to put and where...

N1L’s picture

bump bump bump

N1L’s picture

Its been a week and still no help!

finedesign’s picture

Sorry I can't be of any help. I'm trying to figure out how to change the sort from alphabetical to chronological.

ddd200’s picture

You have to modify two system files. Below is an example of the chronological sorting.

1. modules/book/book.module
*** book.module.orig 2011-08-02 11:58:41.000000000 +0200
--- book.module.mod 2011-08-18 15:12:04.000000000 +0200
***************
*** 263,269 ****
$nids[] = $book['bid'];
}
if ($nids) {
! $result2 = db_query(db_rewrite_sql("SELECT n.type, n.title, b.*, ml.* FROM {book} b INNER JOIN {node} n on b.nid = n.nid INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE n.nid IN (". implode(',', $nids) .") AND n.status = 1 ORDER BY ml.weight, ml.link_title"));
while ($link = db_fetch_array($result2)) {
$link['href'] = $link['link_path'];
$link['options'] = unserialize($link['options']);
--- 263,269 ----
$nids[] = $book['bid'];
}
if ($nids) {
! $result2 = db_query(db_rewrite_sql("SELECT n.type, n.title, b.*, ml.* FROM {book} b INNER JOIN {node} n on b.nid = n.nid INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE n.nid IN (". implode(',', $nids) .") AND n.status = 1 ORDER BY ml.weight, n.created"));
while ($link = db_fetch_array($result2)) {
$link['href'] = $link['link_path'];
$link['options'] = unserialize($link['options']);
***************
*** 385,391 ****
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $node->book['weight'],
! '#delta' => 15,
'#weight' => 5,
'#description' => t('Pages at a given level are ordered first by weight and then by title.'),
);
--- 385,391 ----
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $node->book['weight'],
! '#delta' => 127,
'#weight' => 5,
'#description' => t('Pages at a given level are ordered first by weight and then by title.'),
);
***************
*** 1069,1077 ****
$sql = "
SELECT b.*, m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.*
FROM {menu_links} ml INNER JOIN {menu_router} m ON m.path = ml.router_path
! INNER JOIN {book} b ON ml.mlid = b.mlid
WHERE ". implode(' AND ', $match) ."
! ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";

$data['tree'] = menu_tree_data(db_query($sql, $args), array(), $item['depth']);
$data['node_links'] = array();
--- 1069,1077 ----
$sql = "
SELECT b.*, m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.*
FROM {menu_links} ml INNER JOIN {menu_router} m ON m.path = ml.router_path
! INNER JOIN {book} b ON ml.mlid = b.mlid INNER JOIN {node} n ON b.nid = n.nid
WHERE ". implode(' AND ', $match) ."
! ORDER BY ml.weight, n.created";

$data['tree'] = menu_tree_data(db_query($sql, $args), array(), $item['depth']);
$data['node_links'] = array();

2. includes/menu.inc
*** menu.inc.orig 2011-08-03 09:06:53.000000000 +0200
--- menu.inc.mod 2011-08-18 14:56:42.000000000 +0200
***************
*** 828,838 ****
// Select the links from the table, and recursively build the tree. We
// LEFT JOIN since there is no match in {menu_router} for an external
// link.
$data['tree'] = menu_tree_data(db_query("
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
! FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
WHERE ml.menu_name = '%s'". $where ."
! ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
$data['node_links'] = array();
menu_tree_collect_node_links($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
--- 828,843 ----
// Select the links from the table, and recursively build the tree. We
// LEFT JOIN since there is no match in {menu_router} for an external
// link.
+ // $data['tree'] = menu_tree_data(db_query("
+ // SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
+ // FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
+ // WHERE ml.menu_name = '%s'". $where ."
+ // ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
$data['tree'] = menu_tree_data(db_query("
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
! FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path LEFT JOIN {book} b ON ml.mlid = b.mlid LEFT JOIN {node} n ON b.nid = n.nid
WHERE ml.menu_name = '%s'". $where ."
! ORDER BY n.created", $args), $parents);
$data['node_links'] = array();
menu_tree_collect_node_links($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
***************
*** 935,945 ****
// Select the links from the table, and recursively build the tree. We
// LEFT JOIN since there is no match in {menu_router} for an external
// link.
$data['tree'] = menu_tree_data(db_query("
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .")
! ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
$data['node_links'] = array();
menu_tree_collect_node_links($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
--- 940,955 ----
// Select the links from the table, and recursively build the tree. We
// LEFT JOIN since there is no match in {menu_router} for an external
// link.
+ // $data['tree'] = menu_tree_data(db_query("
+ // SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
+ // FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
+ // WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .")
+ // ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
$data['tree'] = menu_tree_data(db_query("
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .")
! ORDER BY ml.weight ASC", $args), $parents);
$data['node_links'] = array();
menu_tree_collect_node_links($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
***************
*** 1005,1011 ****
// Use db_rewrite_sql to evaluate view access without loading each full node.
$nids = array_keys($node_links);
$placeholders = '%d'. str_repeat(', %d', count($nids) - 1);
! $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.nid IN (". $placeholders .")"), $nids);
while ($node = db_fetch_array($result)) {
$nid = $node['nid'];
foreach ($node_links[$nid] as $mlid => $link) {
--- 1015,1021 ----
// Use db_rewrite_sql to evaluate view access without loading each full node.
$nids = array_keys($node_links);
$placeholders = '%d'. str_repeat(', %d', count($nids) - 1);
! $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.nid IN (". $placeholders .") ORDER BY n.created"), $nids);
while ($node = db_fetch_array($result)) {
$nid = $node['nid'];
foreach ($node_links[$nid] as $mlid => $link) {
***************
*** 1013,1018 ****
--- 1023,1029 ----
}
}
}
+ // ksort($tree);
_menu_tree_check_access($tree);
return;
}
***************
*** 1032,1042 ****
// The weights are made a uniform 5 digits by adding 50000 as an offset.
// After _menu_link_translate(), $item['title'] has the localized link title.
// Adding the mlid to the end of the index insures that it is unique.
! $new_tree[(50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid']] = $tree[$key];
}
}
// Sort siblings in the tree based on the weights and localized titles.
! ksort($new_tree);
$tree = $new_tree;
}

--- 1043,1053 ----
// The weights are made a uniform 5 digits by adding 50000 as an offset.
// After _menu_link_translate(), $item['title'] has the localized link title.
// Adding the mlid to the end of the index insures that it is unique.
! $new_tree[(50000 + $item['weight']) . $item['mlid']] = $tree[$key];
}
}
// Sort siblings in the tree based on the weights and localized titles.
! // ksort($new_tree);
$tree = $new_tree;
}

adam_b’s picture

Could you add leading 0's to the numbers? ie 01, 02, 03... 09, 10, 11, etc. This would be the simplest way to solve the problem.

There are a couple of modules which add "natural sort" functionality to Views etc, but I don't think they handle numbers - they just ignore words like "the", "a", "an", etc.