Topic: Show pages tagged with current page slug
I use this in template files to show a list of page titles and page contents that are tagged with the page slug of the current page. It is a way to group into categories by tag. Not exactly 'Custom Post Types', but it can be useful.
For example, let's create some pages for a restaurant menu:
copy index.template.php to a new template file called restaurant-menu.template.php
insert the code below after <?php echo Site::content(); ?>
create a new page with name 'Menu Example''
set the new page to use the new 'restaurant-menu' template
give the page a slug 'menu-example''
create new pages like Omelette, Hamburger, and Pasta and give them all tag 'menu-example'
<?php $tagged_items = Pages::$pages->select('[contains(tags, "'. Page::slug() .'") and status="published"]', 'all'); foreach ($tagged_items as $tagged_item){ $content = Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $tagged_item['id'] . '.page.txt')); echo ('<h3>'.$tagged_item[title].'</h3>'); echo ('<p>'. $content .'</p>'); } ?>
Cheers!