I'm using the following code to generate a listing pages of recent blog entries.
$listlength="10";
$content_type = 'blog';
unset ($output);
$prev_day = '';
$result1 = pager_query("SELECT n.title, n.nid, n.uid, n.created, u.name, c.comment_count
FROM {node} n INNER JOIN {users} u ON n.uid =u.uid
INNER JOIN {node_comment_statistics} c ON n.nid = c.nid
WHERE n.type = '$content_type' AND n.status = 1
ORDER BY n.created DESC");
while ($node = db_fetch_object($result1)) {
$day = format_date($node->created, 'custom', 'l, jS F');
if ($day != $prev_day) {
$output .= "<h2>$day</h2>";
$prev_day = $day;
}
$output .= "<p>" . l($node->title, "node/$node->nid") . "<br>" . "<small>» Posted by " . l($node->name, "user/$node->uid") . ". There " . format_plural($node->comment_count, 'is 1 answer', 'are %count answers') . " so far." . "</small></p>";
}
$output .= theme('pager', NULL, $listlength);
print $output;
The output is:
Day, xth of the Month
Title of node (url with title)
» Posted by USER (link to user). There are (comment count) answers so far.
I would like to also include the taxonomy terms in which the blog post has been made:
Day, xth of the Month
Title of node (url with title)
» Posted by USER (link to user) in Taxonomy Term1, Taxonomy Term 2. There are (comment count) answers so far.
Now, I see in the API that there is a function called taxonomy_node_get_terms which performs this function, however, I am uncertain how to include it in the query.
Any help much appreciated.
Comments
Boink!
Anyone? Man, these SQL questions are pretty unpopular.
Anyone?
*bump*
Here is one way to get the taxonomy term (4.6)
Using 4.6 you can
Place this before the line that sets $output and add $term_list where you want them.
(side note, in 4.7 the terms are already in $node->taxonomy)
Thanks!
Doesn't quite work yet, but that's probably me being stupid. Thanks for taking the time Nevets.
--Case.
Minor point
Minor point, replace the 27 (first function call) with the node id you want terms for. Possibly use $node->nid depending on the context.