2

Excuse my template tagging if is looks confusing. I am fairly new to ExpressionEngine and using categories is my latest adventure.

On this following page Click here under the "more sport" section of this page I want to display a max of 4 of the most recent post within it's category, I need to do the same for the other five category.

I have made attempts to this section but it seems to duplicate the same entry post 4 times rather than four different post within the category. This is also happening on my blog roll page Click here

Can someone guide me in the right direction?

      <ul class="post">
   {exp:channel:entries dynamic="yes" sort="asc" status="open" limit="4"}

        {categories}
        <li>
        <a href="{url_title_path='blog/full-post'}">
        <a href="{path='blog/blog-roll'}">
            <div class="featured-tab {url_title}"></div>
        </a>
            <a href="{url_title_path='blog/full-post'}"><img src="{blog_slide_image}" alt="placeholder" class="feature-preview-img"></a>
                <p>{exp:eehive_hacksaw chars="250" append="..."}{feature_copy}{/exp:eehive_hacksaw}</p>
</li>
    {/categories}

    {/exp:channel:entries}

Code for blog roll

<ul class="results-row">
{exp:channel:entries channel="blog" disable="member_data|trackbacks" dynamic="yes"}
{exp:channel:categories channel="blog" style="linear" show_empty="no" }
        <li>
        <a href="{url_title_path='blog/full-post'}">
            <div class="featured-tab {url_title}"></div>
            <img src="{blog_slide_image}" alt="placeholder" class="feature-preview-img"></a>
            <h2>{title}</h2>
            <p>{exp:eehive_hacksaw chars="150" append="..."}{feature_copy}{/exp:eehive_hacksaw}</p>
        </li>
        {/exp:channel:categories}
        {/exp:channel:entries}
        </ul><!-- RESULTS-ROW ENDS HERE-->
5

Good morning!

Let's step back for a moment. First, if you are new to EE and especially categories then I'd recommend reading through this tutorial I wrote a while back.

Basically I think you are trying too hard, and shouldn't need to nest entries tags into category tags like that - it not only shouldn't be necessary but can be a performance drain as well.

On the first question if you are looking to display other entries in the same category as the entry being displayed then look at the related categories mode parameter for the channel entries tag.

If instead it's just a category page showing the most recent 4 entries in a category (and isn't showing an entire single entry) then all you'll need is the template loaded at a category URL with the channel:entries tag and a limit parameter set to 4 (and the tutorial I linked to above would demonstrate this).

I'm not sure what you mean by "tagging" - in EE-land tags are different from categories and require a 3rd party add-on to implement.

| improve this answer | |
  • Love your work @Michael - always a lifesaver!!! – Dan Aug 11 '13 at 23:21
2

As Michael stated in his answer, you will need to use Related Categories Mode parameter. As stated in the docs:

This parameter is intended for use only when you are using the channel tag within “single entry” pages. Single entry pages are ones that show only a single entry, specified by the ID number or URL Title in the URL.

When enabled, this parameter alters the behavior of the {exp:channel:entries} tag, causing it to ignore the entry ID or URL title found in the URL, and instead show a list of entries that are in the same category as the entry specified in the URL. This lets you create a list of entries that are “related” to the primary one specified by the URL.


Your "More Sports" section of the page would look something like:

<ul class="post">
{exp:channel:entries related_categories_mode="yes" limit="4"}
    <li>
        <a href="{url_title_path='blog/full-post'}">
            <div class="featured-tab {url_title}"></div>
        </a>
        <a href="{url_title_path='blog/full-post'}"><img src="{blog_slide_image}" alt="placeholder" class="feature-preview-img"></a>
        <p>{exp:eehive_hacksaw chars="250" append="..."}{feature_copy}{/exp:eehive_hacksaw}</p>
    </li>
{/exp:channel:entries}

Note: I removed the dynamic="yes" sort="asc" status="open" parameters because these are defaults on the channel:entries tag so are a given. You should probably add a channel="" parameter too.

This will return 4 articles in the same categories as the current "detail" article on the page.


You Blog Roll code would look something like:

<ul class="results-row">
{exp:channel:entries channel="blog" disable="member_data|trackbacks" related_categories_mode="yes" limit="4"}
    <li>
        <a href="{url_title_path='blog/full-post'}">
            <div class="featured-tab {url_title}"></div>
            <img src="{blog_slide_image}" alt="placeholder" class="feature-preview-img">
        </a>
        <h2>{title}</h2>
        <p>{exp:eehive_hacksaw chars="150" append="..."}{feature_copy}{/exp:eehive_hacksaw}</p>
    </li>
{/exp:channel:entries}
| improve this answer | |
  • it's doesn't seem to display anything when i add that link – NewBoy Jan 9 '13 at 9:26

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.