Welcome Guest, Not a member yet? Register   Sign In
How handle multiplie categories on the site

Hello everyone! In my development I using CI but this question more in common programming case

Imagine situation like we have a site and multiplie nested categories in it.

category 1.2
category 1.3
category 1.4
category 1.5
category 2.1

and so on...

In every category we have a posts. So question is what will be url of that posts?

for example if we have 3 or 4 nested levels it will be horrible URL, something like


Here we have some problems

1)To find url path for current post we need find all possible categories - what means few DB requests! Bad thing!

2)What if we have search on our site and in result page we have posts even from diff categories trees. For each post we need request DB for URL path of certain post!

So how you guys handle this?

Thoughts... Maybe for all posts create unique url and link to them will be something like /posts/post-url and not start with list of all categories!?

Please help! thanks

(This post was last modified: 09-17-2015, 06:42 AM by PaulD. Edit Reason: Added bold for clarity )

Not necessarily that URL structure. Each post will have a URL friendly name perhaps or an id, so the url to the post itself could be




where post is the controller displaying posts and view or view_post is the method.

As for category url's, the same applies. Each category will have an id or perhaps a url friendly unique name, so your url to a category is simply category/view/category_name or category/view/category_id

You can then recreate page trails and parents from a simple parent column in the database.

The same goes for your search. If searching posts, then the results are displayed and the links to them are simply post/view/post_id. A simple function to get the parent details would be something like, is parent=0, no, get parent details. Is that parent's parent=o (ie top level), no, get the parents parent parent, is that =0, yes, then create the trail or category list from the info.

That last paragraph might be a bit messy, sorry, but I think you can get the idea.

Hope that helps,

Best wishes,


hi! very thank you for answer. You write me a usual way of handling simple category or post controllers. If i have one category there is no problem, but i have until 4 nested levels. So if i will do like i mention before then for each post or category i need search all parents - what takes some extra work like DB requests.

Even if it will be one request for post or category parent when i show list - thats already a bad idea i think

So main question maybe would be the best to separate posts and categories?

Posts list
categories/category1/categor2/category3 <-- list of posts of category3

Category list
categories/category1/category2 <-- list of categories that is subcategories for category2

one post
categories/category1/categor2/category3/post1 <-- one post url

So this implement structure very hard i think

Maybe separate categories and posts like below

For categories



for posts


I just dont know how will be the best choice cause this hard implementation creates huge amount of DB requests!


Theme © iAndrew 2016 - Forum software by © MyBB