I am desperately seeking some assistance with not really a huge problem, but one that has completely baffled me and once the answer is realize Im going to spend the rest of the day thinking of how obvious it was and how stupid I was for missing it. What I need to do is configure a block that will display only the most recent image of a specific gallery. Can I do this with out making significant changes to the image module? It seems there has to be a way to do it just through the administer menus, but I can't get it right. Please help a new user just trying to make a go of it! Thanks.

Comments

comike011’s picture

Can somebody please help with this...Im begging from the bottom of my heart.

mitomac’s picture

You need to change the image_get lastest function

Specifically change the second db_query_range to 'ORDER BY created DESC' as below :


/**
 * Fetch the latest N image(s) - optionally from a given term.
 */
function image_get_latest($count = 1, $tid = 0) {
  if ($tid != 0) {
    $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {term_node} tn LEFT JOIN {node} n ON n.nid=tn.nid WHERE n.type='image' AND n.status=1 AND tn.tid=%d ORDER BY n.created DESC"), $tid, 0, $count);
  }
  else {
    $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.type='image' AND n.status=1 ORDER BY created DESC"), 0, $count);
  }
  $output = array();
  while ($nid = db_fetch_object($result)) {
    $output[] = node_load(array('nid' => $nid->nid));
  }
  return $output;
}


mitomac’s picture

Sorry, misread your question. I had just helped a friend have his latest image display always the most recent uploaded image, not an update image.

You could always hardcode the Select statement to use the appropriate gallery...

My bad

comike011’s picture

Where would I go about hardcoding the select statement in? Thanks.

As a follow up, the answer was achieved, thanks for everybody's help.

sepeck’s picture

Rather than hacking the image module and then forgetting during an update, you try a php snippet? This snippet is from 4.6 may may work without to much modifications.

Display latest image from a gallery

I haven't tried it yet on a 4.7 site so not sure, use on test site, etc etc...

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

sepeck’s picture

I tested this on a 4.7 install and it worked just fine.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide