By geohelper on
Using the CCK and contemplate modules, I'm trying to create a custom template that displays a node as well as other nodes in the same category. The code below is working, but I'd like to be able to link to the related nodes' url_alias.
Is there an easier way to do this, or should I just query the alias while looping the related results?
$tid = NULL;
if (is_array($node->taxonomy) && count($node->taxonomy) > 0) {
foreach($node->taxonomy as $key => $value) {
if (is_object($value) && isset($value->tid)) {
$tid = $value->tid;
}
}
}
if (isset($tid)) {
$sql = "SELECT p.* ";
$sql .= "FROM content_type_product AS p ";
$sql .= "INNER JOIN term_node AS t ON p.nid = t.nid ";
$sql .= "WHERE t.tid = '{$tid}' AND p.nid != '{$node->nid}'";
}
Comments
Views
You should be able to do what you want with Views quite easily:
http://drupal.org/project/views
Docs here:
http://drupal.org/handbook/modules/views
embed view into node
Thanks, I didn't realize you could embed a view into a node...
http://drupal.org/node/85769
Exclude current node
This is useful for excluding the current node from the view:
http://drupal.org/node/131547
To get a node's URL alias ...
drupal_get_path_alias('node/34');