0

Going through old templates and trying to clean up some stuff.

One page I have is a category page. This displays a list of entries within a category that is specified within segment 3 of a url like so example.com/walks/category/myexamplecategory

My template is currently like so (some bits stripped out)...

{exp:gwcode_categories channel="walks" cat_url_title="{segment_3}" output_depth="1" entry_count="yes"}
<h5 class="headline">{cat_name}</h5>
  <p>We have <strong>{entry_count}</strong> 
  {if entry_count == 1}walk{/if}
  {if entry_count != 1}walks{/if} in <strong>{cat_name}</strong>
  </p>
{/exp:gwcode_categories}
{exp:cat2:id category_url_title="{segment_3}" category_group="2" parse="inward"}
  {exp:channel:entries channel="walks" status="open" category="{category_id}" disable="member_data|category_fields" show_expired="yes" paginate="bottom" limit="12"}
    <h2><a href="{title_permalink='walks/view'}">{title}</a></h2>
    <p>{description}</p>
    {categories}
        <a href="{path='walks'}">{category_name}</a></span>
    {/categories}
  {/exp:channel:entries}
{/exp:cat2:id}

So as you can see, I'm using Cat2 and GWCode plugins. I'm wondering if theres a simpler way to achieve this, potentially using native tags as opposed to third party ones? Many thanks!

1

I may be missing something here but this seems really straightforward. The following EE code would display all entries in the myexamplecategory category:

  {exp:channel:entries channel="walks" disable="member_data|category_fields" show_expired="yes" paginate="bottom" limit="12"}
    <h2><a href="{title_permalink='walks/view'}">{title}</a></h2>
    <p>{description}</p>
    {categories}
        <a href="{path='walks'}">{category_name}</a></span>
    {/categories}
  {/exp:channel:entries}

That wouldn't get your count of entries in each category that you have in the first chunk of code, but I can't see the point of the cat2 add-on in your latter bit of code. So long as the URL is a valid EE category URL containing both the /category/ keyword and a valid URL title the channel:entries tag will dynamically filter to just returning entries in that category.

1
  • Tyanks for sharing this. I tidied this up the other day by dropping the Cat2 part and using category="{segment_3_category_id}" (as I have the Low Seg2cat plugin). You've just made me realise that I didn't need this either. I hadn't realised that the entries tag will dynamically return the correct entries! Super! Presumably for the first part to still have entry counts I need to use an addon/plugin. Still a lot cleaner already though!
    – shorn
    Dec 24 '14 at 16:28

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.