allow browsing next/previous image in gallery
phacka - May 3, 2006 - 20:33
| Project: | Image |
| Version: | 6.x-1.x-dev |
| Component: | image_gallery |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
hi
i'd like to have next/previous buttons when viewing image, just like image-4.5.0
here is a little start, this code is a quick hack not ready for merging, but it works for me
ORDER BY n.title ASC should match your sort order in image_gallery.module
1. change function theme_image_body:
function theme_image_body($node, $size) {
return ph_image_navigation($node) . image_display($node, $size) . $node->body;
}
2. add this to image.module
# ph hack
function ph_image_navigation(&$node)
{
global $base_url;
$previous=0;
$next=0;
$tmp_prev=-1;
$output="<br>";
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, _image_gallery_get_vid());
$term = array_pop($terms);
$res = db_query("SELECT n.nid FROM {term_node} t, {node} n WHERE t.tid=$term->tid AND n.nid=t.nid ORDER BY n.title ASC");
for($i=0;$i<db_num_rows($res);$i++)
{
$nidvalue=db_result($res,$i);
if($previous!=0 && $next==0)
{
$next=$nidvalue;
}
if($nidvalue == intval($node->nid))
{
$previous=$tmp_prev;
}
$tmp_prev=$nidvalue;
}
$output .= '<div class="links">';
if($previous>0) { $output .= "<a href=\"$base_url/node/$previous#pict\"><< previous photo <<</a> "; }
else $output .= "<< previous photo << ";
$output .= " || ";
if($next>0) { $output .= "<a href=\"$base_url/node/$next#pict\">>> next photo >></a>"; }
else $output .= ">> next photo >>";
$output .= '</div><a name=pict></a><br>';
return $output;
}
#1
Sorry, but:
http://drupal.org/node/318
and
Why? What's happended to Drupal's theme functionality?
#2
#3
+1 This works OK. I would use « and %raquo instead of the double > or < and only use one pipe in between, but other than that, it is a basic and necessary function.
-1 Code needs work.
#4
Is this a feature that can be implemented? I'd really like to see this functionality in this module. I see a few different work arounds but all of them are confusing and do not work properly.
#5
thx for the hack... but there is a mysql error if u dont select any term.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND n.nid=t.nid ORDER BY n.title ASC' at line 1 query: SELECT n.nid FROM term_node t, node n WHERE t.tid= AND n.nid=t.nid ORDER BY n.title ASC in ...\includes\database.mysql.inc on line 120.
#6
Yes. This SQL error is easily fixed by adding an
if ($terms)around the terms SQL search:<?phpfunction ph_image_navigation(&$node) {
global $base_url;
$previous=0;
$next=0;
$tmp_prev=-1;
$output="<br>";
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, _image_gallery_get_vid());
if ($terms) {
$term = array_pop($terms);
$res = db_query("SELECT n.nid FROM {term_node} t, {node} n WHERE t.tid=$term->tid AND n.nid=t.nid ORDER BY n.title ASC");
for($i=0;$i<db_num_rows($res);$i++) {
$nidvalue=db_result($res,$i);
if($previous!=0 && $next==0) {
$next=$nidvalue;
}
if($nidvalue == intval($node->nid)) {
$previous=$tmp_prev;
}
$tmp_prev=$nidvalue;
}
$output .= '<div class="links">';
if($previous>0) { $output .= "<a href=\"$base_url/node/$previous#pict\"><< previous photo <<</a> "; }
else $output .= "<< previous photo << ";
$output .= " || ";
if($next>0) { $output .= "<a href=\"$base_url/node/$next#pict\">>> next photo >></a>"; }
else $output .= ">> next photo >>";
$output .= '</div><a name=pict></a><br>';
return $output;
}
}
?>
#7
Okay this probably isn't the best place to post this but I mocked up a way to add this bit of HTML into a block as well as the body.
<?php
function image_block($op, $delta = 0) {
switch ($op) {
case 'list':
$block[0]['info'] = t('Latest image');
$block[1]['info'] = t('Random image');
$block[2]['info'] = t('Image Nav');
return $block;
case 'view':
if (user_access('access content')) {
switch($delta) {
case 0:
$images = image_get_latest();
$block['subject'] = t('Latest image');
$block['content'] = l(image_display($images[0], 'thumbnail'), 'node/'.$images[0]->nid, array(), NULL, NULL, FALSE, TRUE);
break;
case 1:
$images = image_get_random();
$block['subject'] = t('Random image');
$block['content'] = l(image_display($images[0], 'thumbnail'), 'node/'.$images[0]->nid, array(), NULL, NULL, FALSE, TRUE);
break;
//CUSTOM BLOCK ADDED TO ENABLE TAX. BASED NAVIGATION
case 2:
$node->nid = arg(1); //COULDN'T FIGURE OUT A BETTER WAY TO GET NODE OBJECT IN HERE---HELP?
$block['subject'] = t('Image nav');
$block['content'] = ph_image_navigation($node);
break;
}
}
return $block;
}
}
?>
#8
any chance of getting a next/previous hack for the 4.6 module as well? there's a phptemplate solution here, but I'm using xtemplate.
#9
I am posting this against the HEAD.
This really is a BASIC image gallery feature and should be implemented.
#10
if someone wants to roll a patch for this i'll review it. i agree that it would be a useful feature.
#11
marked http://drupal.org/node/134919 as duplicate ...
#12
is it working in 6.x?
#13
subscribe
I do not like to hack the image.module, first because I'm not confident with php, but will be happy if
there is a way to have this done with a template.php code. Any hint?
#14
I used thickbox to get next, prev... is that the type of functionality being suggested? But the next/prev would just appear on the image node itself? What if the image is in more than one gallery?
#15
thought this is related: http://drupal.org/node/193056
#16
Above didnt work in my drupal 6. So I made couple of changes and following scripts works perfectly on my site http://freekool.com/image
Below is the updated code you can use to show prev and next in Drupal 6.
1. change function theme_image_body (same as descriibed above by phacka)
function theme_image_body($node, $size) {
return ph_image_navigation($node) . image_display($node, $size) . $node->body;
}
2. Add following php code in image.module
<?phpfunction ph_image_navigation(&$node) {
global $base_url;
$previous=0;
$next=0;
$tmp_prev=-1;
$output="<br>";
$terms = taxonomy_node_get_terms_by_vocabulary($node, _image_gallery_get_vid());
if ($terms) {
$term = array_pop($terms);
$res = db_query("SELECT n.nid FROM {term_node} t, {node} n WHERE t.tid=$term->tid AND n.nid=t.nid ORDER BY n.created DESC");
while ($nidvalue=db_result($res)){
if($previous!=0 && $next==0) {
$next=$nidvalue;
}
if($nidvalue == intval($node->nid)) {
$previous=$tmp_prev;
}
$tmp_prev=$nidvalue;
}
$output .= '<div class="links">';
if($previous>0) { $output .= "<a href=\"$base_url/node/$previous\"><< previous photo <<</a> "; }
else $output .= "<< previous photo << ";
$output .= " || ";
if($next>0) { $output .= "<a href=\"$base_url/node/$next\">>> next photo >></a>"; }
else $output .= ">> next photo >>";
$output .= '</div><a name=pict></a><br>';
return $output;
}
}
?>
#17
did anyone else try this?
#18
I just tried it out on http://www.gochsheim-evangelisch.de/image and it seems to work. The sort order of the images must be set according to the order in the gallery. Mine ist set to "order by file name", so I changed the syntax to ORDER BY n.title ASC - no problems till now.
#19
marked http://drupal.org/node/316773 as duplicate
marked http://drupal.org/node/288543 as duplicate
#20
I've just posted a pager module (choice of 4 pagers via settings) for Image nodes for 5.x-1.x-dev and a patch for Image_gallery at http://drupal.org/node/317902 if anyone has any interest. I'm not on Drupal 6 yet so I have no idea how difficult it would be to adapt. The patch adds Nodeorder support (if used) and the breadcrumb no longer loses the plot if images have multiple taxonomy terms. Works fine here, but it's my first attempt at a module.
#21
That's great, I will give it a try. Thanks very much for your contribution.