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.

Controlling menu display/content by segments

October 10, 2012 1:26am

Subscribe [2]
  • #1 / Oct 10, 2012 1:26am

    pixelcamp

    26 posts

    Hi I’ve got a menu built with category parents and children and I’m displaying the children (menu items) using the category parent id:

    {if segment_3 == 'category-name1'|'category-childname1'|'category-childname2'|'childname3'}   style="linear"  category_id"15" incl_self="no"{/if}
    {if segment_3 == 'category-name2'|'category-childname1'|'category-childname2'|'childname3'}   style="linear"  category_id"15" incl_self="no"{/if}
    {if segment_3 == 'category-name3'|'category-childname1'|'category-childname2'|'childname3'}   style="linear"  category_id"15" incl_self="no"{/if}
    <li {if category_url_title == segment_3} class="current"{/if}>
    <a href="http://{path=">{category_name}</a></li>

    and works for:

    http://www.mywebsite.com/category/category-name

    BUT

    if I type in the URL

    http://www.mywebsite.com/category/

    the menu goes all over the place and pulls in all entries, what would be the best way to control the url here

    something like…

    {if segment_3 [b]DOESN'T EQUAL[/b] 'category-name3'|'category-childname1'|'category-childname2'|'childname3'}   style="linear"  category_id"15" incl_self="no"{/if}
    
    <li><a href="http://{path=">page [b]NOT found[/b]</a></li>

    Would low-seg2cat be the answer?]

    Thanks

  • #2 / Oct 11, 2012 3:05pm

    Kevin Smith

    4784 posts

    Hi pixelcamp,

    I’m a bit perplexed by the template code you’ve got here without its context. It looks like the conditionals are within something meaningful, but I’m not sure what that is. Could you post back the full template? Or at least the parts of the template surrounding this?

  • #3 / Oct 11, 2012 5:57pm

    pixelcamp

    26 posts

    Thanks Kein,

    my main prob is that as soon as I type something after my category indicator (in the url) ie mywebsite.com/template/catgeory/I can type anything here and it will display, I want to disable this so anything other than category urls will redirect to a 404, is there a simple way to do that (rather not use strict urls) Thanks

  • #4 / Oct 15, 2012 6:45pm

    Robin Sowell

    13255 posts

    Are you going to have a channel entries tag on the page?  If so- could you do a 404 for no results?  If so- then just add a conditional so

    {if segment_3 == 'category' && segment_4 == ''} 404 redirect….

    Of course- you might want something different for a ‘valid’ no results….  In which case- perhaps use the query module- do a query for a category_url_title = {segment_3}, and no results does a 404.

    Either of those approaches do the trick?

  • #5 / Oct 15, 2012 6:58pm

    pixelcamp

    26 posts

    Thanks, works for my parent categories (Product1 | Product2 | Product3), so ‘ProductBlahadasadsasd’ redirects, but I also have child categories assigned to a parent - to display a menu (Product1_red | Product1_blue | Product1_yellow) and when I click these even though it should match the segment -its triggering the redirect when I don’t want it to… any ideas?

    Cheers guys

  • #6 / Oct 16, 2012 3:15am

    pixelcamp

    26 posts

    I wonder if there are benefits to building the menu like this?

    Product1 (Category)
    –Product1_red (entry title)
    results - assigned to categories

    instead of

    Product1 (Category parent)
    –Product1_red (Category child)
    results - related links

    seems its the child categories which aren’t being recognised as a category_url_title hence the unexpected redirect

    Cheers

  • #7 / Oct 16, 2012 3:01pm

    Robin Sowell

    13255 posts

    Hrm- it should work, I think.  Which method did you go with- can you paste the simplified code?

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

ExpressionEngine News!

#eecms, #events, #releases