Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When you display all the images in a gallery they are showed sorted by date, the newest is first. This is also how the prev/next buttons should take you.
In most cases, for new galleries, sorting by date or nid probably will give the same result since you get increasing dates and increasing node ids as you keep adding images.
If you edit an image and if you change the date (Authored on) the you will start running into problems. Here is the code I used to properly navigate by date (and this code also fixes the DESC/ASC sort order):
function next_prev($current_nid, $type, $btn_type, $label, $class) {
$query = db_query("SELECT tid FROM {term_node} WHERE nid = $current_nid;");
$tid = db_result($query);
$query = db_query("SELECT created FROM {node} WHERE nid = $current_nid");
$current_created = db_result($query);
$sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid ";
$sql .= "INNER JOIN {term_data} r ON t.tid = r.tid WHERE n.type = '".$type."' AND n.created ";
switch ($btn_type) {
case "next":
$sql .= "< ";
$sort = "DESC";
break;
case "prev":
$sql .= "> ";
$sort = "ASC";
break;
default:
return NULL;
break;
}
$sql .= $current_created ." AND r.tid = ". $tid ." AND n.status = 1 ORDER BY n.created $sort;";
$query = db_query($sql);
$result = db_fetch_array($query);
if (!$result) {
$query = db_query("SELECT name FROM {term_data} WHERE tid = $tid;");
$name = db_result($query);
return l("Back To $name", "$type/tid/$tid", array("title" => $name, "class" => $class));
} else {
return l($label, "node/".$result['nid'], array("title" => $label, "class" => $class));
}
}
Comments
Help!!!
I'm trying to modify the code above to work with another table (draggableviews_structure) generated by "DraggableTable".
The table "draggableviews_structure" has:
view_name
nid
delta
args
value
Instead of sort by date I would like to sort by "value".
The code I have:
It's not working...
What I'm doing wrong?
Can somebody help me?