Category index page

HowardB
Sr. Bludit
Posts: 40
Joined: Sat Jun 04, 2022 1:31 pm
Been thanked: 2 times

I'm very happy with what I have achieved www.spainonthisday.com and I have several categories and wondered whether an index page - ie listing all the pages in one category is possible to configure to make the site more user-friendly

Many thanks.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Do you mean a list of all titles or a list of all titles by categories?
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
HowardB
Sr. Bludit
Posts: 40
Joined: Sat Jun 04, 2022 1:31 pm
Been thanked: 2 times

a list of titles by category


For example for category/features i want to see a list of all the feature pages rather than having to look at each page in return

Many thanks

in documents i find

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();
}
?>

But I am unsure which page i should use this code to obtain index pages each listing their own category content
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

For example if there is a category "food" you can create a template food.php with the code above.

In addition to this you have to modify the template index.php adding the template food.php to the condition $WHERE_AM_I, and use for example:

Code: Select all

<?php
   if ($WHERE_AM_I == 'page') {
      if ($page->slug() == "food") {
         include(THEME_DIR_PHP.'food.php');
      } else {
         include(THEME_DIR_PHP.'page.php');
      }
   } else {
      include(THEME_DIR_PHP.'home.php');
   }
?>
Now you can create a page with the title (slug) "Food" which uses the template food.php.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
HowardB
Sr. Bludit
Posts: 40
Joined: Sat Jun 04, 2022 1:31 pm
Been thanked: 2 times

Many thanks

So I need to repeat this process for each category and once this is completed the additional pages should appear in the correct category list

Correct?
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Yes. This is the easy way.

But you can also use one template with $categoryKey = $page->slug().
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
HowardB
Sr. Bludit
Posts: 40
Joined: Sat Jun 04, 2022 1:31 pm
Been thanked: 2 times

I'll try that

Many thanks for great support
HowardB
Sr. Bludit
Posts: 40
Joined: Sat Jun 04, 2022 1:31 pm
Been thanked: 2 times

Where should this single line
$categoryKey = $page->slug().

go - in the index.php somewhere here

<?php
// Bludit content are pages
// But if you order the content by date
// These pages works as posts

// $WHERE_AM_I variable detect where the user is browsing
// If the user is watching a particular page/post the variable takes the value "page"
// If the user is watching the frontpage the variable takes the value "home"
if ($WHERE_AM_I == 'page') {
include(THEME_DIR_PHP . 'page.php');
} else {
include(THEME_DIR_PHP . 'home.php');
}
?>

or how as a single template

Many thanks
HowardB
Sr. Bludit
Posts: 40
Joined: Sat Jun 04, 2022 1:31 pm
Been thanked: 2 times

I have made this template

<?php
// Category key
$categoryKey = 'features';

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

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

// Print the pages title related to the category "features"
foreach ($category->pages() as $pageKey) {
$page = new Page($pageKey);
echo $page->title();
}
?>

i have made a change to index.php as follows

<?php
if ($WHERE_AM_I == 'page') {
if ($page->slug() == "features") {
include(THEME_DIR_PHP.'features.php');
} else {
include(THEME_DIR_PHP.'page.php');
}
} else {
include(THEME_DIR_PHP.'home.php');
}
?>

Then i went to a written page in the features category to edit and under advanced options and wrote in the template area features.php but it didn't work - the new templates didn't appear

I have placed all the new category templates php in /bi-themes/andy/php/
so features.php

But i couldn't find the created page with the single title
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

HowardB wrote: Fri Jul 08, 2022 12:30 pm I have made this template

[...]

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

[...]
This has to be:

Code: Select all

// Print the category name
echo 'Category name: ' . $category->name();
Then i went to a written page in the features category to edit and under advanced options and wrote in the template area features.php but it didn't work - the new templates didn't appear
This feature does not work.

You have to create a new page with the title "Features" (slug "features").
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Post Reply