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.

Display category name, and URL best practises

January 02, 2013 5:24am

Subscribe [3]
  • #1 / Jan 02, 2013 5:24am

    Hi,

    How do you make EE display category name? I can’t seem to get that tag to work.
    I have a slider which displays an image, slide title and slide category. Image and title show up fine, but category name doesn’t.

    Here’s my current slider code:

    {exp:channel:entries channel="frontpage_slider" sort="desc" dynamic="no" limit="3" disable="member_data|pagination"}
           <div class="slide-section item {if count == 1}active{/if}">
            <a href="http://{url_title_path=news}">_         {excerpt_image}_        </a>
            <div class="carousel-caption">
             <div class="carousel-item-category"><span class="icon awe-tags"></span>
              {exp:channel:category_heading}
              <a href="http://{url_title_path=news/category}">{category_name}</a>
              {/exp:channel:category_heading}
             </div> 
             <h3><a href="#">{title}</a></h3>
    <p>        </div><br />
           </div><br />
           {/exp:channel:entries}

    And also, what is the best approach regarding URL structure.
    Let’s say I have 3 first-level menu elements: Home, Products and Contact us.
    Products and Contact us contains second-level elements too.

    I would like the URL to reflect the menu element the customer is currently browsing.
    Eg. http://www.mydomain.com/products/memory or www.mydomain.com/contact-us/sales-departement.

    Both of those menus use the same template. Would I still need to create a new template group for each main menu element (‘products/index.html’ and ‘contact-us/index.html’), and then just copy the template, or is there an easier and better way to do it?

    I’m working on a real website, with about 7 top-level menu elements, all with the same template, and would like to keep my code and templates as DRY as possible, but still retain unique URLs that reflect to the customer where he is currently.

    Regards
    Kristoffer

  • #2 / Jan 02, 2013 5:38pm

    Roi Agneta

    352 posts

    Hi Kristoffer,

    Re: using the Channel:Category_Heading tag, that will only show results when you are on a page that was accessed with a category in the url, e.g. /my_page/3 Not sure I understand enough about what you are trying to do in order to make recommendations.

    Re: best practices for urls, there is a tradeoff between making templates overly complicated (loads of conditionals and url sniffing) versus a more simple approach that results in more templates.  The basic url structure is template_group/template/entry.  You can leave out the template group if it is the default one and you can set up the index.php template in the default group to show different content based on the url.  Say you have two top level “pages”, products and services.  You can put conditionals in the index template that look at the url segments and take action based on what is there, e.g.

    {if segment_1 == products}
    ..show product stuff
    {/if}

    The url mysite.com/products will go to the index template in the default group since there is no template named “products”.  Same with services.  You could extend that to include a second level, but things get even more complicated.

    Personally, I prefer to created separate template groups and templates when the content structure get beyond very simple.

    Hope that helps!

    Roi

  • #3 / Jan 02, 2013 5:58pm

    Roi Agneta,
    Thanks for your input!

    Regarding category name: I just want to show which category a slider item was posted in. People see a picture, and overlayed on that picture is the title, and the category the slide belongs to.

    I guess the best approach regarding the URL structure would be to have different templates as you suggest, as the menu on this site is BIG (10 top level items containing more than 40 sub-menu items).

    Thanks! 😊

  • #4 / Jan 02, 2013 8:50pm

    Roi Agneta

    352 posts

    Got it!  Do not use the category_heading tag.  Instead, use this:

    {categories}
          {category_image} [optional]
          {category_name}
    {/categories}

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

ExpressionEngine News!

#eecms, #events, #releases