[support] need to check publication status in block code I use

Florent JOUSSEAUME florent.jousseaume at makina-corpus.com
Mon Jul 28 09:10:47 UTC 2008


Hello,

I think the better soluce is to add the status condition in the SQL
statement. In your request, you don't get the status value for each
node. Getting the filtered value since the DB is the simplest soluce.

$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  AND n.status
= 1 ORDER BY RAND() LIMIT 3";

Florent,

Neil: esl-lounge.com a écrit :
> 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



More information about the support mailing list