Hi,
As we know drupal just lumps all taxonomies into one pile, and says print $terms. What I want to achieve for node.tpl.php is so that the Categories are displayed above the content, and tags are displayed below links only in full node view.
If I understand it correctly, there is no way to do this directly in node.tpl.php, so in template.php we need to define which $vid is Categories and which ones are Tags , and then pass it to node.tpl.php and simply print $categories and print $tags. But I can't find any correct snippet that will differentiate and define which vocabulary is $categories and which one is $tags inside template.php.
So far I found few similar solutions:
http://gerardmcgarry.com/blog/drupal-get-a-comma-separated-list-categori...
http://www.kobashicomputing.com/creating-a-comma-delimited-taxonomy-list...
http://drupal.org/node/38768 (but only for 5.x)
... but none of them
so far in my node.tpl.php I've got:
<?php if ($terms) { ?><div class="taxonomy"><?php print $terms ?></div><?php } ?> //This is where I need to show only Categories and no tags. Would be lovely if we could just say print $categories
<?php print $content ?>
<?php if (arg(0) == 'node'): ?> // Because I want the Tags to display only in Full view of the node
<!-- <?php
$term_links = array();
// "implode" makes the terms comma-separated
foreach ($node->taxonomy as $term) {
$term_links[] = l($term->name, 'taxonomy/term/' . $term->tid);
}
print implode(', ', $term_links);
?>
-->
<?php if ($terms) { ?>
<div class="tags">
<span><?php print t('Tags'); ?>:</span> <?php print $node_terms; ?>
</div>
<?php } ?> // Here I need the
<?php endif; ?>
Someone, please help with defining and differentiating the $categories from $tags inside the template.php
Or is there a better way to achieve this?
Comments
In template.php, add
In template.php, add this:
Then, your node.tpl.php could be simplified to this:
That didn't work
Thanks mverbaar for taking time to reply and help.
I used the code you gave me, but it gave out "Tags: Array", and the categories are not displaying at all.
Indeed my Categories vid is 1 and Tags is 2, so I didn't change those. In my theme (newswire) template.php there is already a function function newswire_preprocess_node(&$vars, $hook) { so I just inserted this code before the last } of that function.
in my node-story.tpl.php I inserted the codes you gave me, but no Categories are being displayed and where the tags should display, it says "Tags: Array"
Any idea what I did wrong?
Thanks again!
I just tested the code and it
I just tested the code and it worked here. (Printing categories as
ul+lis and tags comma-seperated.)Can't really think of anything that could be the problem at the moment ...
Perhaps put a
drupal_rebuild_theme_registry();at the top of template.php while developing, just in case. Although I'm pretty sure that can't be it ...