Closed (fixed)
Project:
Node Auto Term [NAT]
Version:
6.x-1.1-beta3
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Nov 2009 at 10:17 UTC
Updated:
18 Mar 2010 at 22:20 UTC
Hi.
I've recently created a little function for themers using NAT wich can output terms by vocabulary in three different ways:
Links are created with URL alias if they are defined. Since it's my first "serious" code and I haven't seen any php snippet with the same functionality I'd like to share it. Is there any kind of project for NAT documentation?
Kind regards.
PS.- Here is a little example of use:
In your theme you put:
<p><strong>Plain text:</strong> <?php print phptemplate_vterms($node, 8, FALSE, FALSE);?></p>
<p><strong>Term link:</strong> <?php print phptemplate_vterms($node, 8, TRUE, FALSE);?></p>
<p><strong>NAT link:</strong> <?php print phptemplate_vterms($node, 8, TRUE, TRUE);?></p>
...and you get
<p><strong>Plain text:</strong> <span class="term">Half life 2</span>, <span class="term">Half life 2 - Episode one</span>, <span class="term">Half life 2 - Episode two</span>, <span class="term">Portal</span>, <span class="term">Team fortress 2</span></p>
<p><strong>Term link:</strong> <a href="/categoria/juego/half-life-2">Half life 2</a>, <a href="/categoria/juego/half-life-2-episode-one">Half life 2 - Episode one</a>, <a href="/categoria/juego/half-life-2-episode-two">Half life 2 - Episode two</a>, <a href="/categoria/juego/portal">Portal</a>, <a href="/categoria/juego/team-fortress-2">Team fortress 2</a></p>
<p><strong>NAT link:</strong> <a href="/juego/portal">Half life 2</a>, <a href="/juego/half-life-2">Half life 2 - Episode one</a>, <a href="/juego/half-life-2-episode-one">Half life 2 - Episode two</a>, <a href="/juego/half-life-2-episode-two">Portal</a>, <a href="/juego/team-fortress-2">Team fortress 2</a></p>
Comments
Comment #1
ManyNancy commentedHi please share! How did you do this? Thanks.
Comment #2
NoRandom commentedI've changed a bit the function and now it allows 4 different modes of terms.
Put this function in your template.php file:
(my natural language is spanish so it's possible I left some spanish comments)
And that's it, you just need to modify your theme and call to this funcion any time you need it. For example:
Link for terms of vocabulary 5 wich leads to the standard taxonomy page...
Link for term of vocabulary 3 that leads to the node wich created that terms through NAT...
Regads.
PS.- I'm not a programmer so the code can be improved a lot, SURE.
Comment #3
ManyNancy commentedThanks for the snippet. I was hoping I could figure this out from your code but, do you know how to return just the NAT term. Just the name without a link or anything?
Thanks.
Comment #4
NoRandom commentedYes, simply put in your template:
print phptemplate_vterms($node, 3, 'raw', FALSE);So, in short, you have to choose between:
Comment #5
ManyNancy commentedComment #6
NoRandom commentedI don't know much about this issues, but I think the problem comes from the block.
The function uses the $node variable wich -I think- is not available from blocks directly. You should "load" first the node (maybe using global or maybe with the drupal function to do it) and then you could call the function.
To check it you could try to print directly the node variable in your block with
print_r($node);. If it doesn't output anything, that's the problem.UPDATE
I think there is an error in your code:
'content' => print phptemplate_vterms($node, 2, 'raw', FALSE)it should be
'content' => phptemplate_vterms($node, 2, 'raw', FALSE)without "print".
Comment #7
ManyNancy commentedComment #8
anantagati commented