EEConf 2024 is around the corner! EEConf 2024
Hi,
I’m working with EE occasionally and I have one problem.
Imagine that you have a blog (or any other channel) where you can add entries.
You need to create two new blog entries and one entry is for category called “Security” and second entry is for category called “Fire”.
First entry you create and select category ”Security” because you have created that category before creating new entry. After publishing first one you create second entry and now you create new category called “Fire” with (great) option where you can create new category during publishing your entry.
Now you have two entries where each one of them belongs to the different category.
Problem:
How to display only entries that belong to specific category?
If you ”click” on category called ”Security”, on a predefined template is shown only entries for that category? I know that there is possible to define category within channel display tag but I want to generate that dynamically because user can create bunch of random categories and bunch of entries sorted in that bunch of categories and ”hard coding” every time is not an option.
Please if someone can provide answer for this kind of problem with example, I was looking all over the forum and there are some similar questions but no simple answers.
Ty
Assuming you have a channel called “blog” and a template group and index template, i.e. blog/index here’s a basic example for your index template:
<!--Show category links-->
{exp:channel:categories channel="blog"}
< a href="{path='blog/index'}">{category_name}</a > <!-- link points to your blog/index template -->
{/exp:channel:categories}
<!--Show blog posts-->
{exp:channel:entries channel="blog"}
{title}
{/exp:channel:entries}
The category link URL’s will be something like example.com/blog/category/C1 or example.com/blog/category/category-name depending what your settings are - EE will automatically add the /category segment for you, this is then used to filter content by that category ID or name.
So if you land on a non category page the channel:entries tag will show all blog posts from all categories (max 100 by default). If you land on a category page the channel:entries tag will only show posts from that category.
To display entries that belong to a specific category dynamically in ExpressionEngine (EE), you can use the channel: entries tag with the category parameter. This allows you to filter entries by category without hardcoding each category name.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.