Related nodes to the current node by taxonomy term (2)


/ Published in: PHP
Save to your folder(s)

Here is a simpler list format without the Term name, sorted by date, filtered for published and images, and is rendered correctly by the theme.


Copy this code and paste it in your HTML
  1. <?php
  2. if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
  3. $nid = (int)arg(1);
  4. $terms = taxonomy_node_get_terms($nid);
  5. $output = "<ul>";
  6. foreach($terms as $term){
  7. $sql = "SELECT DISTINCT n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.status = 1 AND tn.tid = $term->tid AND n.nid != $nid AND n.type <> 'image' ORDER BY n.created DESC LIMIT 6";
  8. $result = db_query(db_rewrite_sql($sql));
  9. if (db_num_rows($result)) {
  10. while ($anode = db_fetch_object($result)) {
  11. $output = node_title_list($result);
  12. }
  13. }
  14. }
  15. return $output;
  16. }
  17. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.