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.

Clean URL's with categories / sub categories

February 10, 2008 12:46pm

Subscribe [5]
  • #1 / Feb 10, 2008 12:46pm

    John Macpherson

    113 posts

    Just going properely with EE in the last few days.

    Iv read numerous posts asking for some kind of straight url structure and been experimenting with different methods.

    Most of my pages are in the same format so i didnt really see a point in making numerous repeated templates so iv made a kind of ‘oop’ code structure. I understand its advised to use templates to structure data but this to me is cleaner and more ‘resuable’. I could be missing some crucial part understanding of EE though…

    Not sure if this is of any use to anyone and there may well be parts that could work better so feel free to post changes, but it may help any newbies out there looking for some kind of quick way to get categories and subc’s working.

    http://www.domain.com/category/sub-category/page_url

    {embed="file" main_catter="enter root cat id here"}
    {if segment_2=="" AND segment_3==""}
    
    {exp:subcategories root_node="{embed:main_catter}"}
    <li><a href="http://{path=">{category_name}</a></li>
    {category_description}
    {/exp:subcategories}
    
    {if:elseif segment_2!="" AND segment_3==""}
    
    {exp:query sql="SELECT cat_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
    {exp:weblog:entries weblog="web-pages" category="{cat_id}" dynamic="off" sort="asc"} 
    <li><a href="http://{title_permalink={segment_1}/{segment_2}}">{title}</a></li>
    {summary}
    {/exp:weblog:entries}
    
    {/exp:query} 
    
    {if:elseif segment_3!=""}
    
    {exp:weblog:entries weblog="web-pages" url_title="{segment_3}"} 
    <h1>{title}</h1>
    {body}
    {/exp:weblog:entries}
    
    {/if}

    Pleae post any methods that will work better and feel free to move this to a better section mods. Hope it may be of use to someone

  • #2 / Feb 10, 2008 3:35pm

    tbritton

    714 posts

    The beauty of this is that is allows one to bring native dynamic=“on” functionality back into a place where dynamic=“off”, for instance, in a sidebar or elsewhere, or anywhere you want to force parsing of the URL structure into a result - OR NOT. I love how it lets you decide how you want the content to display - either dynamically or selectively as determined by whether you pass a variable or not!

    What I’m not sure is grasped at this point by you yet, my friend, is that this much of this is the already-built-in functionality of the “big three” weblog tag pairs with dynamic=“on”, if I’m not mistaken. But your code adds a nice tool to the arsenal!

    So, the normal tag behavior could simply be applied after the first if:

    {if segment_2=="" AND segment_3==""}
    
    {exp:subcategories root_node="{embed:main_catter}"}
    <li><a href="http://{path=">{category_name}</a></li>
    {category_description}
    {/exp:subcategories}
    
    {if:else}
    
    {exp:weblog:entries weblog="web-pages" dynamic="on" sort="asc"} 
    
    {categories}
    {if segment_3==""}
    <li><a href="http://{path=template_group/template}">{title}</a></li> {!-- where you want the data displayed --}
    {summary}
    {/categories}
    
    {if:else}
    <h1>{title}</h1>
    {body}
    
    {/if}
    
    {/exp:weblog:entries}

    Does the same thing as what you did, just uses dynamic=“on”, for what its worth. And note the usage of title_permalink=. I generally use path= instead here. You pull the template group and template from the existing url here, but it can point to any template group and template you wish. However, your technique (which self-references the template the link is sitting in) is a nice idea. The category and entry ids would carry over automatically into the refreshed view of the same template.

    A nice piece of code! Thanks! I’ll find further uses for this somewhere! I already use hard-coded segment tests to recycle the index page for use as a landing, categories or entries page as you are, but this embedded formulation you’ve come up with is excellent for that!

    Terry

  • #3 / Jun 01, 2009 1:35am

    OrganizedFellow

    435 posts

    Am I the only one confused by this?

    There is no {exp:subcategories} tag!

  • #4 / Jun 01, 2009 11:55am

    BridgingUnit

    214 posts

    I think it’s using this 3rd party plugin: http://ellislab.com/forums/viewthread/27220/

  • #5 / Jun 01, 2009 3:35pm

    OrganizedFellow

    435 posts

    @BridgingUnit Thank you, I was totally lost there for a moment.

  • #6 / Jun 01, 2009 6:03pm

    BridgingUnit

    214 posts

    @OrganizedFellow - it wasn’t until you flagged it up that I realised that it was out of the ordinary myself 😊

  • #7 / Jun 17, 2009 11:50pm

    Big Skillet

    364 posts

    Has anyone had any luck getting “next_entry, prev_entry” to work in the single entry portion of the {if} statement?  I haven’t been able to get it to work.  It seems like EE isn’t recognizing it as a single entry page since the URL is dynamic… or am I missing something?

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

ExpressionEngine News!

#eecms, #events, #releases