0

I have to add a text, that describes the current category but I have to put it outside the channel tag with a single entry and if the category_id is for example number 5, I have to get a text that describes that specific category.

Can anyone help me with an idea how to do that?

3
  • There are several ways to approach this, which will depend on the specific use-case; could you provide an outline or copy/paste of your template markup? Jan 6 '14 at 16:21
  • It's just channel:entries tag with single entry displayed. I need to get the category_id of the entry and add it outside the channel:entry tag to Channel Category Heading Tag, which will display the category_description field. {exp:channel:category_heading} <h1>{category_name}</h1> {if category_description} <p>{category_description}</p> {/if} {/exp:channel:category_heading}
    – ispasov
    Jan 6 '14 at 23:13
  • Is the entries category present in the URL? ie. www.my site.co/category/entry_title Jan 31 '16 at 8:03
1

In its simplest form you'll need another channel entries tag & a free module to get the category info... like this:

{exp:channel:entries url_title="{segment_2}"}
  {exp:gwcode_categories entry_id="{entry_id}"}
    <h1>{cat_name}</h1>
    <p>{cat_desc}</p>
  {/exp:gwcode_categories}
{/exp:channel:entries}

We're asking the channel entries tag to get the entry via its url_title (this would be segment_x with x representing where it is in the URL).

We're then using a must have plugin by GWCode - gwcode categories which uses the entries entry_id to pull in the category assigned to it. With this module you can get parent info, child info and a whole host of other category related data.

Of course, if the category is present in the URL you can use GWcode Category to get the info without the exp:channel tag to get the entry_id.

PT:2 Just saw you had Stash as a tag in your original question which requires only one channel entry tag and makes it simpler (of sorts).

Place this at the start of your template…

{exp:stash:set parse_tags="yes" parse_depth="2"} //This is a single entry so need for lists
  {exp:channel:entries url_title="{segment_2}"}
    {stash:my_title}{title}{/stash:my_title}
    {stash:my_content}{my_content_field}{/stash:my_content}
    {exp:gwcode_categories entry_id="{entry_id}"}
      {stash:my_category_title}{cat_name}{/stash:my_category_title}
      {stash:my_category_desc}{cat_desc}{/stash:my_category_desc}
  {/exp:channel:entries}
{/exp:stash:set}

//This above records all the parts of the entry. Then further down the template output all the 'stashed' bits.

<h1>{exp:stash:my_category_title}</h1>
<p class="summary">{exp:stash:my_category_desc}</p>
…
<div class="my_article">
  <p>{exp:stash:my_title}</p>
  {exp:stash:my_content}
</div>
2
  • I had an error message: {exp:stash … No closing tag found. Note: some tags do not require closing. Please consult the module's documentation if you experience problems.
    – ispasov
    Jan 7 '14 at 7:46
  • 1
    I had an errant closing tag without an opening one. Deleted it above. Also, examples here are purely theory you will have to modify to suit your particular scenario. Read the modules docs if you get stuck or errors - aka try solving before replying. Jan 7 '14 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.