You are here

function image_get_latest in Image 5

Same name and namespace in other branches
  1. 5.2 image.module \image_get_latest()
  2. 6 image.module \image_get_latest()

Fetch the latest N image(s) - optionally from a given term.

1 call to image_get_latest()
image_block in ./image.module
Implementation of hook_block.

File

./image.module, line 828

Code

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.changed 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 changed DESC"), 0, $count);
  }
  $output = array();
  while ($nid = db_fetch_object($result)) {
    $output[] = node_load(array(
      'nid' => $nid->nid,
    ));
  }
  return $output;
}