Hello,

I would like to display a list of the most recent nodes on the front page of my site for the top terms...(completed) Now I would like to mix files in with the nodes as well, similar to that of Basecamp.

I am completely lost on this, Google has not helped, neither has the countless Drupal searches. I have wasted extremely too much time on this one little loop, and know that it has to be possible. If any one has been able to accomplish this in the past or point me to a past post or how-to it would be greatly appreciated.

Thanks

Josh

Comments

DGvNp0niToyRspXaaqx3PiQBMn66QXyAq5yrNHpz’s picture

I'm getting there but my code is a little sloppy and I would like to show only three of the selected rows instead of between 3 - 6

If anyone could give a few pointers it would be great

function compare_recent_activity($x, $y) {
 if ( $x[2] == $y[2] )
  return 0;
 else if ( $x[2] < $y[2] )
  return 1;
 else
  return -1;
}
      
function get_recent_activity($hierarchy = 0, $limit = 2) {
  
  //Set global variable to use site URL
  global $base_url;
  
  //Get the current 'Term Id' from the function ($hierarchy) select direct children of current term
  $select_terms = db_query("SELECT * FROM {term_hierarchy} h, {term_data} d WHERE h.parent = '%d' AND d.tid = h.tid AND d.vid != '2' AND d.vid != '5'", $hierarchy);
  while ($return_term = db_fetch_object($select_terms)) {
    //Node Query
    $select_nodes = db_query("SELECT DISTINCT t.*, n.*, u.entity_id, u.dst, p.name FROM {term_node} t, {node} n, {url_alias_extra} u, {users} p WHERE t.tid = '%d' AND p.uid = n.uid AND t.nid = n.nid AND n.nid = u.entity_id AND u.entity_type = 'node' ORDER BY n.created DESC LIMIT %d", $return_term->tid, $limit);
    //File Query
    $select_files = db_query("SELECT DISTINCT * FROM {term_node} t, {upload} u, {files} f, {users} p WHERE t.tid = '%d' AND u.nid = t.nid AND f.fid = u.fid AND f.uid = p.uid ORDER BY f.timestamp DESC LIMIT %d", $return_term->tid, $limit);
    print '<div class="admin-panel" id="termid_' . check_plain($return_term->tid) . '">' . "\n";
    
    //Term information query
    $name = db_query("SELECT t.*, d.*, u.* FROM {term_node} t, {term_data} d, {url_alias_extra} u WHERE d.tid = '%d' AND u.entity_id = d.tid AND u.entity_type = 'taxonomy' LIMIT 1", $return_term->tid);
    while ($names = db_fetch_object($name)) {
      
      //Display Term name and link to term above each box
      print '<h2><a href="' . check_plain($base_url) . '/' . check_plain($names->dst) . '" title="' . check_plain($names->name) . '">' . check_plain($names->name) . '</a></h2>' . "\n";
      while ($return_nodes = db_fetch_object($select_nodes)) {
        //Display last 3 nodes in current term
        $rows[] = array('<a href="' . check_plain($base_url) . '/' . check_plain($return_nodes->dst) . '" title="' . check_plain($return_nodes->title) . '">' . check_plain($return_nodes->title) . '</a>', check_plain($return_nodes->name), format_date($return_nodes->created, 'small'));
      }
      while ($return_file = db_fetch_object($select_files)) {
        //Display last 3 attachments in current term
        $rows[] = array('<a href="' . check_plain($base_url) . '/' . check_plain($return_file->filepath) . '">' . check_plain($return_file->description) . '</a>', check_plain($return_file->name), format_date($return_file->timestamp, 'small'));
      }
    }
      
      //Setup headers to display each as a table
      $header = array(
        array('data' => 'Title'),
        array('data' => 'Posted By'),
        array('data' => 'Posted On')
      );
      
      //Make sure we selected rows      
      if (count($rows)) :
        //sort the rows in descending order by posted date
        usort($rows, 'compare_recent_activity');
        //print out the table
        $output = theme('table', $header, $rows);
      else :
        //No rows were available
        $rows[] = array(array('data' => 'Your selection returned no results', 'colspan' => '4'));
        $output = theme('table', $header, $rows);
      endif;
      
      //Build and output the final table
      print $output;
      
      //Clear out the $rows for the next block of information
      $rows = NULL;

    print '</div>' . "\n";
  }
}


Wolfflow’s picture

Hi, sorry but I'm not a coder, but may be that I can give you some hints and suggestions.
Take a look here : http://drupal.org/node/622604

Regards

Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.