Page List Filter by Attribute
Permalink
I put three different custom attributes to aprox 250 pages.
Now I would like to display three different page-lists on three different pages.
One should display all pages where the attribute 1 ist selected, one for the pages with the attibute 2 and one for the pages with the attibute 3.
If there are two ore all attributes selected in a page it should be displayed in two lists.
Unfortunately all depending forum-blogs are pretty old (2009) and the suggestions are related to an old version of C5 I think.
Can anybody help me please?
Now I would like to display three different page-lists on three different pages.
One should display all pages where the attribute 1 ist selected, one for the pages with the attibute 2 and one for the pages with the attibute 3.
If there are two ore all attributes selected in a page it should be displayed in two lists.
Unfortunately all depending forum-blogs are pretty old (2009) and the suggestions are related to an old version of C5 I think.
Can anybody help me please?
Dear DrBiskit,
thank you for the quick help. I guess I forgot to tel, that the attributes are only checkboxes. So the "if-than-else" actually have to look if the box is checked or not.
To display only the pages with the checked attribut "autograph" I modified the code like this:
Unfortunately it doesn't work. It displays all pages below the parent page. Maybe there must be an "endif" or something?
Best Mathias
thank you for the quick help. I guess I forgot to tel, that the attributes are only checkboxes. So the "if-than-else" actually have to look if the box is checked or not.
To display only the pages with the checked attribut "autograph" I modified the code like this:
<?php defined('C5_EXECUTE') or die("Access Denied."); $th = Loader::helper('text'); ?> <ul> <?php foreach ($pages as $page): // Prepare data for each page being listed... $title = $th->entities($page->getCollectionDescription()); $ag = $page->getAttribute('autograph'); $sv = $page->getAttribute('stichvorlage'); $ed = $page->getAttribute('erstdruck'); ?> <?php if($page->getCollectionAttributeValue('autograph'))?> <li> <h2><?php echo $title ?></h2>
Viewing 15 lines of 18 lines. View entire code block.
Unfortunately it doesn't work. It displays all pages below the parent page. Maybe there must be an "endif" or something?
Best Mathias
Nearly there! You just need to add in the opening + closing curly braces ( i.e. these: { } ) from the if statement - try this:
<?php defined('C5_EXECUTE') or die("Access Denied."); $th = Loader::helper('text'); ?> <ul> <?php foreach ($pages as $page): // Prepare data for each page being listed... $title = $th->entities($page->getCollectionDescription()); $ag = $page->getAttribute('autograph'); $sv = $page->getAttribute('stichvorlage'); $ed = $page->getAttribute('erstdruck'); ?> <?php if($page->getCollectionAttributeValue('autograph')) { ?> <li> <h2><?php echo $title ?></h2>
Viewing 15 lines of 19 lines. View entire code block.
Cool! Thank You! That's it.
I just had to change
to
Otherwise there was displayed a php alert "unexpectet endforeach".
I just had to change
<? } ?>
to
<?php } ?>
Otherwise there was displayed a php alert "unexpectet endforeach".
STOP I was too quick :-)
Suddenly I am not able anymore to get the link to a listed page.
I tried:
It doesn't work. The list is empty.
Than I added:
.
But that causes an alert:
Fatal error: Call to a member function isExternalLink() on a non-object
Here ist the complete code
Suddenly I am not able anymore to get the link to a listed page.
I tried:
<?php echo $nh->getLinkToCollection($cobj)?>
It doesn't work. The list is empty.
Than I added:
$link = $nh->getLinkToCollection($cobj);
But that causes an alert:
Fatal error: Call to a member function isExternalLink() on a non-object
Here ist the complete code
<?php defined('C5_EXECUTE') or die("Access Denied."); $th = Loader::helper('text'); ?> <div class="ccm-page-list"> <ul> <?php foreach ($pages as $page): $title = $th->entities($page->getCollectionDescription()); $link = $nh->getLinkToCollection($cobj); $ag = $page->getAttribute('autograph'); $sv = $page->getAttribute('stichvorlage'); $ed = $page->getAttribute('erstdruck'); ?> <?php if($page->getCollectionAttributeValue('autograph')) { ?> <li>
Viewing 15 lines of 21 lines. View entire code block.
Got it!!!
<?php defined('C5_EXECUTE') or die("Access Denied."); $th = Loader::helper('text'); $nh = Loader::helper('navigation'); $page = Page::getCurrentPage(); <-- this must be here ?> <div class="ccm-page-list"> <ul> <?php foreach ($pages as $page): $title = $th->entities($page->getCollectionDescription()); $ag = $page->getAttribute('autograph'); $sv = $page->getAttribute('stichvorlage'); $ed = $page->getAttribute('erstdruck'); ?> <?php if($page->getCollectionAttributeValue('autograph')) { ?>
Viewing 15 lines of 22 lines. View entire code block.
I haven't tested this, but it should work. This basically tests for the existence of data against 3 attributes (page_blue, page_red, page_green), if it exists, then it prints out that content.
To use the attached file, you need to change the file extension to .php, and add it here:
root/blocks/page_list/templates/
Then select it from the 'custom template' options available against the page list when in edit mode.
Not knowing what type of attribute you're using, or any other details etc I can't be any more specific, but hopefully this will help!