We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Blog Category List Template and Specified URL Structure

How Do I?

philcoffman's avatar
philcoffman
4 posts
4 years ago
philcoffman's avatar philcoffman

Working on my first EE site and I’m stuck on how to structure my templates for the blog categories that results in a clean URL structure. Here’s what I’m trying to achieve (note: index page is my blog roll):

  • Each blog post has multiple category tags. When clicking on a category I want to display a filtered blog roll related only to that category.
  • I’d like that template to have the freedom to adjust the layout some as I might add some additional sidebar info related to that category down the road. So is that a separate template entirely or the same template as the main blog roll but utilizing conditional statements to adjust the layout if we’re on a single category page?
  • I’d like the URL structure for the category page to be the first segment after my domain. So the URL would be “site-domain/category”.
  • URL structure for each post is currently “site-domain/post/post-title” as I have a template group called “post” with an index limiting the channel entries to 1. This works fine, I’m just noting it in case it’s helpful in describing my setup.
  • Right now my index with the blog roll has working categories but the links use {path='site'} in the href which outputs this URL structure: “site-domain/site/category/design”. I came across this solution via an article on how to build a blog in EE, so while it works it’s not the structure I want. A friend of mine who knows EE better than I do (I’m a beginner) says I might have to add some plugins to get this to work, so I have no idea what that entails and where to look.

I’ve heard that it’s tricky trying to manage segment 1 urls, so not sure if I need to forego this whole idea and stick with more native urls.

I’m happy to continue to chase down solutions if I can be pointed in the right direction. Also, I can paste in some template code or answer questions about how I have EE configured if needed. I appreciate anyone’s time with this, thanks!

       
Rob Allen's avatar
Rob Allen
3,105 posts
4 years ago
Rob Allen's avatar Rob Allen

Welcome to the forums

Is your site primarily a blog? If it is you could use your default template group index file to list category data.

In your index template you can do something like this:

{if segment_1 == ""}
  Home page content
{/if}

{if segment_1 == "catgeory"}
  Category content
{/if}

That will give you a category URL like example.com/category/my-category

Another approach is to use a template group called /blog and use that index template so you have a category URL like example.com/blog/category/my-category

Another approach is to use Template routes - https://docs.expressionengine.com/latest/templates/routes.html - these allow you to create custom URL’s that bypass the normal /template-group/template method.

       
philcoffman's avatar
philcoffman
4 posts
4 years ago
philcoffman's avatar philcoffman

All good ideas Rob, thank you for sharing some options. My site is primarily a blog so I see how I could use conditional statements to structure the index template. I’m going to dig into routes as well to see how they could work.

I was able to work up a solution which doesn’t give me originally what I wanted but it functionally works. I essentially opted for a template group called “category” and use that index to render a filtered list of posts based on the category. That nice thing about this solution is it cleanly separates my templates so I can better manage the main index and the category index.

       
Rob Allen's avatar
Rob Allen
3,105 posts
4 years ago
Rob Allen's avatar Rob Allen

Ah good thinking about a “category” template group - I’ve never used that approach but it’ll work.

As you learn you’ll find EE often has many ways to do the same thing 😊

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.