1

Is there anyway to relate a category tag pair to a entries tag pair? I have this code below and I am trying to get the 'long_head' custom category name to relate to the entries being outputted above it. So if the entry above had a category of 'BEANS' I would like the 'long_head' to be the long head from the category 'BEANS'.

Any help would be great.

{exp:channel:entries channel="services" limit="1"}
<div id="page">
    <h2>{title}</h2>
    <div>
        {service_text}
    </div>
</div>
<!-- // page -->
{/exp:channel:entries}

<div id="nxtBack">
    <p><a href="{site_url}" title="Back to Home Page">&larr; Back to Home Page</a></p>
</div>

<div id="rel-work">
    {exp:channel:categories style="none"}
    <h2>{long_head} Projects</h2>
    {/exp:channel:categories}
    <ul>
        {exp:channel:entries channel="work" limit="20" status="New|Open" related_categories_mode="yes" custom_fields="yes"}
        {if no_results}
            <p class="alert">There are currently no related projects to this service in our online portfolio.</p>
        {/if}
        <li>
            <a href="{title_permalink="work/view"}" title="{title}"><img src="{project_th}" alt="{title}" />{if status == "New"}<img src="/_/img/new-work.png" class="new" alt="NEW Project - {title}" />{/if}</a>
            <h3><a href="{title_permalink="work/view"}" title="">{title}</a></h3>
            <h4>{categories backspace="2"}<a href="{path="work"}" title="">{category_name}</a> / {/categories}</h4>
            <p>{project_excerpt}</p>
        </li>
        {/exp:channel:entries}
    </ul>
    <p><a href="{site_url}work" title="View all work">View all work &rarr;</a></p>
</div>
<!-- // rel-work -->
1
  • Can you, please, mark the right answer? – Sobral Nov 6 '13 at 18:16
1

Since you're just outputting a single channel entry at the top, you can just enclose the category section inside the channel:entries loop:

{exp:channel:entries 
    channel='services' 
    limit='1'
    disable='pagination|member_data'
}
    <div id="page">
        <h2>{title}</h2>
        <div>
            {service_text}
        </div>
    </div>
    <!-- // page -->

    <div id="nxtBack">
        <p><a href="{site_url}" title="Back to Home Page">&larr; Back to Home Page</a></p>
    </div>

    <div id="rel-work">
        {categories}
            <h2>{long_head} Projects</h2>
        {/categories}

{/exp:channel:entries}
3
  • I see thanks I will give that ago ... Can that work in practice the other way round. I often wonder if you can enclose entry tag pairs inside category tag pairs? – MarkerMaker May 14 '13 at 10:30
  • That worked fine many thanks for your input. – MarkerMaker May 14 '13 at 15:17
  • You can with NSM Categories. Please mark my question as the answer, thanks. – kmgdev May 14 '13 at 16:39

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.