Page List - filter by attribute value
Permalink 1 user found helpful
I'm having a list of projects containing the (select)attribute 'customers'.
Beneath each project I want to show a page list showing all the projects of a certain customer. So I'd like to filter on the value of an attribute.
I do know how to hardcode it into the template, but that sucks when a new customer need to be added.
Any thoughts, ideas in how to accomplish this? Maybe I over looked a previous topic?
Thanks.
Beneath each project I want to show a page list showing all the projects of a certain customer. So I'd like to filter on the value of an attribute.
I do know how to hardcode it into the template, but that sucks when a new customer need to be added.
Any thoughts, ideas in how to accomplish this? Maybe I over looked a previous topic?
Thanks.
Ok, so I re-tooled the "related pages" block to be a standard page_list block with the awesome select attribute filter option added.
This will be exactly what you're looking for.
Chad
This will be exactly what you're looking for.
Chad
Sounds like I am looking for that! Did you post in the PRB or can you post it here?
Cheers
Cheers
I think the filter needs to look like this:Note the '\n'. The Select AttributeType saves its values with a newline to separate the options.
$pageList = new PageList; $pageList->filterByAttribute('customers', 'select option\n', 'LIKE');
Hi ijessup
I'm using this solution to filter a page list but when I do so it then excludes any external links that the unfiltered list was showing. Do you have any idea how I could filter the list but still include the external links?
Many thanks
Ps thee external links have the required attributes set like the pages do
I'm using this solution to filter a page list but when I do so it then excludes any external links that the unfiltered list was showing. Do you have any idea how I could filter the list but still include the external links?
Many thanks
Ps thee external links have the required attributes set like the pages do
Are you using a custom version of c5? I'm not sure what you're asking is possible since, typically anyways, you can't apply attributes to external links.
Hi there
You can add all attributes to an external link as you can a page you just need to visit the Page Search page rather than the Sitemap. The external links usually show up in a page list just as regular pages, but when I add this code to filter by attribute it is missing them from the list.
Thanks
You can add all attributes to an external link as you can a page you just need to visit the Page Search page rather than the Sitemap. The external links usually show up in a page list just as regular pages, but when I add this code to filter by attribute it is missing them from the list.
Thanks
Ha! I'm still learning things after all these years. Neat!
Here's where I think the problem is coming from. When you update the attribute, the change isn't getting saved to the PageSearchIndex table.
Looking at the code at lines 214-216 of ~/concrete/core/models/collections.php, it looks like externally linked pages (specifically any "alias" pages) are ignored when doing the reindexing step.
Therefore, the filtered searches will always come back without the external links.
Judging by that, I'm not sure if this is a "bug" or an intended feature. I would say you might be able to comment those lines out and get it to work the way you want, but I'm unsure of any unintended consequences that might happen.
It might be worth submitting as a bug, and seeing where that goes.
Here's where I think the problem is coming from. When you update the attribute, the change isn't getting saved to the PageSearchIndex table.
Looking at the code at lines 214-216 of ~/concrete/core/models/collections.php, it looks like externally linked pages (specifically any "alias" pages) are ignored when doing the reindexing step.
Therefore, the filtered searches will always come back without the external links.
Judging by that, I'm not sure if this is a "bug" or an intended feature. I would say you might be able to comment those lines out and get it to work the way you want, but I'm unsure of any unintended consequences that might happen.
It might be worth submitting as a bug, and seeing where that goes.
Check out this thread:
http://www.concrete5.org/community/forums/customizing_c5/how-to-wan...
http://www.concrete5.org/community/forums/customizing_c5/how-to-wan...
That was an useful thread! It did the trick.
Hi folks,
I have worked on a similar stuff for a blog part on a website. I use select attribute to define categories for the post.
Regards,
marc
I have worked on a similar stuff for a blog part on a website. I use select attribute to define categories for the post.
<?php $pl = new PageList(); $ak = 'select_attribute'; $av = 'select_value_to_check'; $pl->filterByAttribute($ak, '%'.$av.'%', 'like'); $pl->setItemsPerPage($num); // get the numbers of items/page from edit dialog switch($orderBy) { // get sort order from edit dialog case 'display_asc': $pl->sortByDisplayOrder(); break; case 'display_desc': $pl->sortByDisplayOrderDescending(); break; case 'chrono_asc': $pl->sortByPublicDate(); break; case 'alpha_asc': $pl->sortByName(); break; case 'alpha_desc': $pl->sortByNameDescending(); break; default: $pl->sortByPublicDateDescending(); } $pages = $pl->getPage();
Viewing 15 lines of 22 lines. View entire code block.
Regards,
marc
Its' not really a "page list" block though as it won't have all the options of parent page and sorting and filtering. Related pages actually randomizes on purpose as well.
Perhaps I will add more options to it to make it more flexible.
ChadStrat