Page 1 of 1

Table of category pages

Posted: Sat Dec 28, 2019 5:32 pm
by saum
Hi,

I'm currently using the theme Alternative and would like to have a static page with link to it on top right (like the About page). On this page I want to present the links to all pages in a specific category.
Currently I am editing this page and creating the links for the category pages manually.

Is it possible to have something like a table of contents on a page for categories, which is created automatically?
Something like this:

Title
desc

Title
desc

Thanks in advance!

Re: Table of category pages

Posted: Mon Dec 30, 2019 12:26 am
by Jay
Shouldn't be hard to achieve. Try this

1. create a new, empty static page to list the cat content with an example name catpages
2. check below example code, adjust it to your own requirements, and place somewhere in page.php file located in theme directory

Code: Select all

<?php
if ($page->slug() == 'catpages' && $page->isStatic() ) {
	$category = getCategory('YourCategory');
	foreach ($category->pages() as $pageKey) {
		$page = new Page($pageKey);
		echo '<h3>'.$page->title().'</h3>';
		echo '<p>'.$page->description().'</p>'; 
	}
}
?>

Re: Table of category pages

Posted: Thu Jan 02, 2020 10:31 am
by saum
Thanks Jay, this worked nicely.

The link to the respective page I got with

Code: Select all

$page->permalink(false)
One further question:
Is it also possible to create some kind of snippet for this, which could be inclueded in the WISIWYG editor and would then be replaced with this table of contents?

Thanks and happy new year!

Re: Table of category pages

Posted: Fri Jan 03, 2020 11:33 pm
by Jay
Just posted a proof of concept to what you wanted to achieve, but you already used respective function to get the url.

When it goes to parsing php code within wysiwyg editor I wouldn't hit it for security reasons. But afaik there are some plugins doing such thing but you would have to check them by yourself and modify accordingly.

From the other hand this could be achieved with bludit's basic functionality if you only want to get such "TOC" on top or at the end of article.
Just look for a thread about "template" field in article options. You can use it to include appropriate template file (let's say toc.php) before article's content along with article's customfield for a category name.