1 (edited by monstrahost 2016-04-27 17:38:15)

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

  • 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'


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 ('

'.$tagged_item[title].'

'); echo ('

'. $content .'

'); } ?>

Cheers!

monstrahost's Website

Re: Show pages tagged with current page slug

@monstrahost

Nice idea smile

I am intending to modify the Page/ Blog plugin to allow for custom fields and values.
So in theory you could add a field called Category and give it a value you can then use as you wish.

Would this prove useful for you?

Will

will's Website

Re: Show pages tagged with current page slug

It certainly could.

I'd think it would be most useful if it acted like the blog plugin and could be enabled separately from it to extend the 'pages' plugin. I'm trying to wrap my head around how I would want it to work...

I'm not sure I would want the custom fields on all content. For example, to run with the restaurant menu use case, it would be really cool to be able to add fields like 'category' and 'price' to sub-pages of a menu page, but I wouldn't want those fields on all pages.

Alternatively, just extending the standard 'pages' plugin to have custom fields could be really useful for certain types of sites, like those that list things with many properties.  It would make online shop creation pretty easy if you used paypal or gumroad or something like that.

monstrahost's Website