I would really appreciate someone helping me with
just a tiny bit of SQL code for some block code I got off d.o
here is the code:
<!-- 4 returned for each term, ordered by nid
descending, meaning new will always be at top -->
<?php
if (arg(0)
== 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
$nid = (int)arg(1);
$terms = taxonomy_node_get_terms($nid);
$output = "<span class='whole-list'>";
foreach($terms as
$term){
$sql = "SELECT n.title, n.nid FROM {node} n INNER
JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = $term->tid AND n.nid !=
$nid ORDER BY RAND() LIMIT 3";
$result =
db_query(db_rewrite_sql($sql));
if (db_num_rows($result))
{
$output .="<h5
style='color:#900;font-weight:bold;margin-top:3px;'>$term->name</h5><ol
class='each-term'>";
while ($anode =
db_fetch_object($result)) {
$output .= "<li>".l($anode->title,
"node/$anode->nid")."</li>";
}
$output.="</ol>";
}
}
$output .= "</div>";
return
$output;
}
?>
it shows other nodes with the same taxonomy terms
and I use it for a lot of Related Blog Posts, Related Forum Posts, type blocks.
But it doesn't check for publication status so I need to add "where status = 1"
at some part of the code. But where? Would I therefore also need to add n.status
in the SELECT part of the query?
any help much appreciated...these blocks are an
important part of my site but I'm getting nodes in moderation going into them
too.
Thanks
Neil