1

I'm struggling to understand what is the "proper" way to build URLs in EE. I think I want my URLs to be built in such a way that it can take advantage of EE's dyanamic="yes", etc. Right now, I can build URLs and use certain segments to display the content I want, but I'm not sure if I am doing it correctly.

Say I am building a simple forum. I have a Channel forum_topics which has Categories. I want to do the following:

  1. Display a page with a list of categories. Each category will link to a list of Channel entries with that category. Also, ideally, I'd like to list the last 10 entries for each category on this page. Is this possible?
  2. Display a list of Channel entries for a given category. Each channel entry will link to that entry's single entry page.
  3. Display the single entry page.

I can do it, but I'm just not sure if I am doing it the "EE way." Here are the snippets of how I'm doing it:

1. FIRST template: loop through categories, create list of links to SECOND template

    {exp:channel:categories
        category_group="1"
        status="open"
        style="linear"
    }
        <a href="/forums/{category_id}/">{category_name}</a>
    {/exp:channel:categories}


2. SECOND template: use segment_2 in {exp:channel:entries}, set {entry_id} as 3rd segment

    {exp:channel:entries
        category="{segment_2}"
        channel="forum_topics"
    }

        <a href="{url_title_path='/forums/topics/{entry_id}/'}">{title}</a>
    {/exp:channel:entries}


3. THIRD template: use segment_3

    {exp:channel:entries
        channel="forum_topics"
        entry_id="{segment_3}"
    }

        <h1>{title}</h1>
    {/exp:channel:entries}

Any suggestions?

1 Answer 1

4

I wouldn't say that there is a right or wrong way to go about this (as long as you keep an eye on performance bottlenecks in the template debugger, which you should be doing all the time anyway)... Whilst EE does have some built-in ways of interpreting your URLs (http://www.jamessmith.co.uk/articles/expressionengine_url_schematic) there's no reason you have to use those ways, and if your templates are working the way you want and they're efficient then there's no need to change.

With that said...

For listing entries by category you can use the Category Archive tag. It's one of the worst tags available in EE as it's both lacking in power/features and is quite inefficient... but there you go.

Here's "the EE way" of setting this up...

For your first template, the category links would link to standard category pages - by which I mean URLs that contain either the category trigger word (as defined in your settings), or a category identifier, that looks for example like "C5". You can do this automatically using the {path...} variable. This allows your second template to automatically filter your channel entries so you won't need to specify category="{segment_2}".

For your second template's links you could simply use {entry_id_path=forums/topics} or {url_title_path=forums/topics} - I'd recommend the latter for better SEO. No need to have both the entry id and the url title in there unless you're pulling content from more than one channel (url titles ARE allowed to be duplicated for entries in different channels).

For your third template you then don't need entry_id="{segment_3}" (or url_title="{segment_3}") as this will be automatically assumed in the absence of dynamic="no".

ExpressionEngine URL Schematic

2
  • Thanks James. I'm still trying to understand all these. About the first template: does this mean that I will have a page that only list links to the categories? When a user clicks on that link, they will be sent to a page with a list of Channel entries that have that category? If so, the page that lists on links of categories would be very content-lacking. It would be nice if at least some of the Channel entries would be listed. Is this possible? Commented Jul 5, 2013 at 20:50
  • For the second template, say I use {entry_id_path=forums/topics} or {url_title_path=forums/topics}. It means that the {entry_id} or the {url_title} would appear in the 3rd segment. Are you saying that EE would still know to look in the 3rd segment? What if I pass it {url_title_path=forums}; this means that the {url_title} would appear in the 2nd segment. Would EE know that? If so, how would EE know the difference between www.domain.com/forums/my-first-topic (a Chnanel entry) versus www.domain.com/forums/P2 (pagination)? Commented Jul 5, 2013 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.