ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is the category archive tag dynamically controlled by the url?

May 10, 2012 4:50pm

Subscribe [2]
  • #1 / May 10, 2012 4:50pm

    Stephen T

    127 posts

    I’ve never had an occasion to use the Category Archive tag before and have two quick questions on it.  I have a page where I want to show all the channel entries for a particular channel organized by category.  So I’m using this tag:

    {exp:channel:category_archive channel="projects" style="linear" disable="category_fields" orderby="title" sort="asc"}
      {categories}<h2>{category_name}</h2><p>{/categories}<br />
        <ul><br />
          {entry_titles}<br />
            <li><a href="http://{path=">{title}</a></li><br />
          {/entry_titles}<br />
        </ul><br />
    {/exp:channel:category_archive}

    However, I also want to give users the option of only seeing a single category using the same template if they click on a category link.  So if they visit http://www.site.com/projects they get all channel entry organized by the category archive tag, but if they visit http://www.site.com/projects/category/category_one the category archive tag would only show them the entries from category_one.  This doesn’t seem to work though.  Does the category archive tag not filter entries dynamically by the url like the channel entries tag does?  I know that I could point the category link to a separate template and use the channel entries tag there to filter the results by category, but I was looking for a more efficient way.

    Also, when I use the code above, it does not output the the <ul> and </ul> tags.  Does the category archive tag ignore anything outside of the {categories} and {entry_titles} tag pairs?

    I’m running EE 2.5.

    Thanks for your help!

     

  • #2 / May 11, 2012 1:40pm

    Dan Decker

    7338 posts

    Hi Stephen,

    This should be behaving dynamically. Go to Admin->Channel Administration->Global Preferences and check “Use Category URL Titles In Links?”.

    If that doesn’t work, you can have a look at Seg2Cat.

    I look forward to your reply!

    Cheers,

  • #3 / May 11, 2012 3:12pm

    Stephen T

    127 posts

    Hi Dan,

    Thanks for getting back to me.  Unfortunately it doesn’t seem to be working.  I already had the “Use Category URL Titles in Links” parameter set to “Yes” with the “Category URL Title” set to “category”, but the category archive tag isn’t filtering the results based on the URL.  So http://www.site.com/projects and www.site.com/projects/category/category_one are giving me the same set of full results.

    I know I could use Seg2Cat for this, but since you’ve confirmed that this should be native functionality I’d like to figure out why it’s not working properly.  Do you have any other ideas?  I’m using category indicators in the URL in other places on the site with the channel entries tag and everything is working fine. It just doesn’t seem to work with the category archive tag.

    Also, I had one other question that got lost up in the original post.  When I use the code in my original post, it does not output the the <ul> and </ul> tags.  Does the category archive tag ignore anything outside of the {categories} and {entry_titles} tag pairs?

    Thanks!

  • #4 / May 15, 2012 5:16pm

    Dan Decker

    7338 posts

    Hi Stephen,

    {egg_on_face}
    After testing and then asking one of our developers, Category Archives is *not* dynamic… so it will not automatically filter based on the URL.
    {/egg_on_face}

    However, I tested your code exactly as above, changing the channel name, and got the output you expect. I tested in ExpressionEngine 2.3.1

    Sorry for the confusion!

    Cheers,

  • #5 / May 17, 2012 10:54am

    Stephen T

    127 posts

    Hi Dan,

    Thanks for looking into this more.  Good to know that the Category Archives tag isn’t dynamic.  I’ll use a workaround.

    I’m still seeing the issue where the ul tags aren’t showing up in the output html.  Here’s the exact code I’m using in the template:

    {exp:channel:category_archive channel="projects" style="linear" disable="category_fields" orderby="title" sort="asc" show_empty="no"}
      {categories}<h2>{category_name}</h2><p>{/categories}<br />
      <ul><br />
        {entry_titles}<br />
          <li><a href="http://{path=">{title}</a></li><br />
        {/entry_titles}<br />
      </ul><br />
    {/exp:channel:category_archive}

    And here’s the html output on the site from that code:

    <h2>Category Title</h2>
    <p><li><a href="http://www.siteurl.com/projects/project1">Project 1</a></li><br />
    <li><a href="http://www.siteurl.com/projects/project2">Project 2</a></li><br />
    <li><a href="http://www.siteurl.com/projects/project3">Project 3</a></li>

    This is on EE 2.5.  Can you replicate this or is it just an issue on my side?  I’m not seeing this problem with any other tags, just the category archives tag.

    Thanks for your help!

  • #6 / May 22, 2012 1:04pm

    Dan Decker

    7338 posts

    Hi Stephen,

    I think I got the output you are after using this:

    {exp:channel:category_archive channel="sandbox" style="linear" disable="category_fields" orderby="title" sort="asc" show_empty="no"}
      {categories}<h2>{category_name}</h2><p>{/categories}<br />
        <br />
        {entry_titles}<br />
        <ul><br />
     <li><a href="http://{path=">{title}</a></li><br />
        </ul>    <br />
    {/entry_titles}<br />
    {/exp:channel:category_archive}

    Including the ul tags inside the entry_titles tag pair seems to do the trick.

    Cheers,

  • #7 / May 22, 2012 2:35pm

    Stephen T

    127 posts

    Hi Dan,

    Thanks for getting back to me.  When I include the code exactly as you have it above, it outputs a ul tag around each li tag.  So the output is:

    <h2>Category One</h2>
    <p><ul><br />
       <li><a href="http://www.siteurl.com/projects/project1">Project 1</a></li><br />
    </ul><br />
    <ul><br />
       <li><a href="http://www.siteurl.com/projects/project2">Project 2</a></li><br />
    </ul><br />
    <ul><br />
       <li><a href="http://www.siteurl.com/projects/project3">Project 3</a></li><br />
    </ul></p>
    
    <h2>Category Two</h2>
    <p><ul><br />
       <li><a href="http://www.siteurl.com/projects/project1">Project 1</a></li><br />
    </ul><br />
    <ul><br />
       <li><a href="http://www.siteurl.com/projects/project2">Project 2</a></li><br />
    </ul>

    Which looks a bit odd on the front end and isn’t the output I want.  Any chance this is a bug where it ignores anything outside of the entry_titles or categories ee tags?  It seems like anything I put outside of those two tags doesn’t show up on the site.

  • #8 / May 25, 2012 2:16pm

    Dan Decker

    7338 posts

    Hi Stephen,

    I went ahead and filed this bug report.

    Is there anything else I can assist you with?

    Cheers,

  • #9 / May 25, 2012 2:26pm

    Stephen T

    127 posts

    That should do it.  Thanks for your help - glad to know it’s a bug and not just something obvious I was missing.  I’ll follow the bug report for updates.

  • #10 / May 30, 2012 10:48am

    Charcoal Marketing

    112 posts

    Since the category archive tags are not dynamic do you have a work around for making it dynamic or organizing sub categories and their entries?

  • #11 / May 31, 2012 1:49pm

    Dan Decker

    7338 posts

    Hey Kyle,

    Thanks for your question!

    Have look at Child Categories, and of course, Seg2Cat - always handy!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases