4

I would like to be able to have the url-structure like

http://example.com/category_name/entry_url_title

Now i know that the default structure in ExpressionEngine is template_group/template_name. The thing i would like to avoid is having to create an entire new Template Group when adding a page group. Also that would seem to make the creation of menus a lot simpler and dynamic.

Is this making any sense or am i going about this problem all wrong?

I'm happy to elaborate if you something is missing in this question. Any help/insights would be enormously appreciated!

Thanks.

  • 2
    To me it sounds like you might be mis-using categories. Ideally, categories - like tags - should be a low-level form of content organisation. What happens if an entry has more than one category? Also, have you checked out the native Pages module? – James Smith Oct 23 '13 at 16:23
  • I feel the same way, but don't really see any other way to get the behaviour i want (adding pages to sections, and adding sections). The way i understand, "Pages" works sort of that way, only i have to create the URL "manually", so the page wouldn't have any real connection to its URL segments. I would like to be able to get all the pages that belong to "segment_1". Do you understand what i mean? – andersandersson666 Oct 24 '13 at 8:38
4

Yes, just have your index template in your default group catch it (strict 404's may interfere with this though).

Use Low Seg2Cat to identify the category, you'll need to check for none found, no_results and utilise embeds to keep the template clean.

Using something like Template Routes means duplication in all the categories to catch them.

| improve this answer | |
  • Thank you! I will try this, and let you know how it goes. I think this may be what i need. I have done most my work in WordPress earlier, where a thing like this would work pretty much right away. You win some you lose som i guess:) – andersandersson666 Oct 24 '13 at 8:50
4

It depends how dynamic you want the URL to be along with the usage and setup of the site really. If it's just a simple blog/news site then you can set things up on the root URL like that but if there are other sections then you may want to consider including /news/category/entry_url where news is a template group of whatever your content consists of.

Generally though, if you looking to break free from EE's default template routing then your best bet would be to use a routing addon. There are a few which can help out here but my personal favourite is Template Routes. You then have much more customisation of your EE URLs.

| improve this answer | |
  • Yes, i had a look at those addons, and they seem great. However i think i will be using the EE default template routing for some parts of the site, so i'm going to try what Robson and the gang suggested first. Thanks for the answer, it gave me a nudge in the right direction. – andersandersson666 Oct 24 '13 at 8:46
  • As I mentioned it all depends on context. Generally you're better off sticking to EE's default template handling and take a look at how categories work in combination with that. I'd always look to approach it that way, include a category indicator in the URL (something you didn't seem to want in your question), and then use seg2cat to easily get reference to it. It only requires one extra segment to your URL. – Ian Oct 24 '13 at 12:01
4

It depends.

EECMS needs a category URL indicator if you want to use category_name instead of the ugly numeric indicator.

But you can use the really good Low Seg2cat and to put all the code on your index template.

{if "{segment_1_category_id}" == ""}
    {!-- your homepage code --}
{/if}
{if "{segment_1_category_id}"}
    {!-- your code to list all entries of this category --}
    {!-- your single entry code --}
{/if}

This sample doesn't deal with different codes for single entry and for list of entries. I don't know if you need this.

| improve this answer | |
2

The Freeway extension should do the trick for you.

A route looks like this:

/blog/{{username}}/{{category}} => /blog/category/{{category}}

In this case, a URL like "blog/davery/css" will be treated, in EE, as "blog/category/css". Several variables will be available in the template:

{freeway_username} - davery
{freeway_category} - css
{freeway_1} - blog {freeway_2} - davery
{freeway_3} - css
{freeway_4+} - (blank)
{freeway_info} - debug info from Freeway

| improve this answer | |
1

Without knowing exactly what your content is and therefore how the "sections" relate to the "pages" it's hard to give a good answer, however I would probably steer away from categories altogether for this.

An alternative solution might be to use two channels - one for parent sections, another for child pages, and use a relationship field in the section entries to specify which pages are part of that section.

To display these on the front end without using the template_group in segment_1, you'll need to use the Pages module to override the URL on each parent section. You won't need to do this on all the child entries, as your specified template can simply look at segment_2 to fetch the right entry to display (using url_title="{segment_2}" and dynamic="no"). If you want to make this a bit smoother, there is an extension which automatically populates the Pages URI with the entry's url_title on publish: http://devot-ee.com/add-ons/auto-pages-uri ... never tried it myself.

| improve this answer | |
1

Another option would be to use Template Routes http://devot-ee.com/add-ons/template-routes

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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