I need to output the category for an entry a few times in an entry's template.
So I want to get the output from the following and assign to a variable so I can reuse within the template:
{exp:channel:entries channel="product" limit="1" status="open"}
{categories}{category_name}{/categories}
{/exp:channel:entries}"
How do it do that?
Now, you could enable the template to allow PHP, then you could write something like this:
{exp:channel:entries channel="product" limit="1" status="open"}
{categories}
<?php $category = '{category_name}'; ?>
{/categories}
{/exp:channel:entries}
Then you have the {category_name}
stored in the php-variable "category". Later you can reuse it as you wish, like echoing it:
<?php echo $category; ?>
You can even compare it to other EE-tags:
{exp:channel:entries channel="product" limit="1" status="open"}
{if <?php $echo($category) ?> == title}
This title have got the same value as the category!
{/if}
{/exp:channel:entries}
Croxton's Stash: http://devot-ee.com/add-ons/stash does very nearly the same thing NSM Transplant (mentioned by Derek, above) does, and is free. One of these addons would definitely be the easiest way to do what you're trying to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With