Categorized index

Post Reply
drawwwn
Jr. Bludit
Posts: 6
Joined: Sun Feb 26, 2023 12:15 am
Has thanked: 3 times
Been thanked: 1 time

How can I display on homepage only posts from certain category?

I want to make something like:
[ Sport ]
[ posts from Sport category ]
[ Lifestyle ]
[ posts from lifestyle category ]
User avatar
Edi
Site Admin
Posts: 3018
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 39 times
Been thanked: 60 times
Contact:

And where should this be shown? On a page or on in the sidebar?
drawwwn
Jr. Bludit
Posts: 6
Joined: Sun Feb 26, 2023 12:15 am
Has thanked: 3 times
Been thanked: 1 time

Edi wrote: Mon Feb 27, 2023 1:59 pm And where should this be shown? On a page or on in the sidebar?
So, now my homepage is showing all posts no matter what category I set for them.
I want to divide them in 2 separated divs.
One for posts that has "works" category applied and one for the one that has "articles" category.

Something like that:

<h1> Works </h1>
<div> works in here </div>
<h1> Articles </h1>
<div> articles here </div>
User avatar
Edi
Site Admin
Posts: 3018
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 39 times
Been thanked: 60 times
Contact:

There is a tutorial for this in the documentation:

https://docs.bludit.com/en/dev-snippets/categories
drawwwn
Jr. Bludit
Posts: 6
Joined: Sun Feb 26, 2023 12:15 am
Has thanked: 3 times
Been thanked: 1 time

Edi wrote: Mon Feb 27, 2023 5:05 pm There is a tutorial for this in the documentation:

https://docs.bludit.com/en/dev-snippets/categories
so it would be this:

Code: Select all

List all pages related to a particular category:
<?php
        // Category key
        $categoryKey = 'example';

        // The category is an Category-Object
        $category = getCategory($categoryKey);

        // Print the category name
        echo 'Category name: ' . $category->name();

        // Print the pages title related to the category "example"
        foreach ($category->pages() as $pageKey) {
            $page = new Page($pageKey);
            echo $page->title();
        }
?>
User avatar
Edi
Site Admin
Posts: 3018
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 39 times
Been thanked: 60 times
Contact:

Yes, this is an example of the code without any HTML.
drawwwn
Jr. Bludit
Posts: 6
Joined: Sun Feb 26, 2023 12:15 am
Has thanked: 3 times
Been thanked: 1 time

Edi wrote: Mon Feb 27, 2023 7:29 pm Yes, this is an example of the code without any HTML.
It's working, thank you!
Post Reply