This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi,
I'm quite confused regarding the relationship between pages and urls.
My plugin's components are widely based on the Blog plugin, so basicaly this is what I've got for my category page:
title = "Blog Category"
url = "/category/:slug/:page?"
layout = "default"
is_hidden = 0
[blogPosts]
pageNumber = "{{ :page }}"
categoryFilter = "{{ :slug }}"
postsPerPage = 5
noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = "blog-category"
postPage = "post"
==
<div class="container col-sm-9">
{% component 'blogPosts' %}
</div>
which gives this kind of urls:
http://mydomaine.com/category/history
http://mydomaine.com/category/history/2
But I'd like to get rid of the "category" part, so I just removed it from the url code line:
url = "/:slug/:page?"
Now I get urls like these:
http://mydomaine.com/history
But unfortunately it shows all of the posts. The categoryFilter property is not taken into account anymore.
Is it possible to remove the page name from the url and how to do that ?
If you have a page with url=/history
it will take precedance on the one with the url=/:slug/:page?
I suggest keeping a prefix to your url otherwise you will get url clashing with other pages.
Last updated
It should work without, as long as a Category name doesn't conflict with another page's url... but if you want to avoid the potential clash, I would definitely add a prefix folder in the url
After a more in-depth look into your issue, I found that the blogPosts component will ignore the category when a non-existing categoryFilter is provided (looks like it's intentional).
If you'd prefer a different behavior, I suggest writing another component or adding this to your CMS page's php code section:
function onInit()
{
if (! RainLab\Blog\Models\Category::where('slug', $this->param('slug'))->first()) {
return $this->controller->run("404");
}
}
1-5 of 5