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.

Dutchwave
 
RadiantWeb replied on at Permalink Reply
RadiantWeb
hi there. I have a block in the PRB that allows you to show "related pages" based on any given select attribute. The block add-dialog shows a list of all select options after choosing a specific select attribute. Then allows you to choose how many to show.

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
RadiantWeb replied on at Permalink Reply
RadiantWeb
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
Dutchwave replied on at Permalink Reply
Dutchwave
Sounds like I am looking for that! Did you post in the PRB or can you post it here?
Cheers
ijessup replied on at Permalink Reply
ijessup
I think the filter needs to look like this:
$pageList = new PageList;
$pageList->filterByAttribute('customers', 'select option\n', 'LIKE');
Note the '\n'. The Select AttributeType saves its values with a newline to separate the options.
rosie607 replied on at Permalink Reply
rosie607
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
ijessup replied on at Permalink Reply
ijessup
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.
rosie607 replied on at Permalink Reply
rosie607
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
ijessup replied on at Permalink Reply
ijessup
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.
jordanlev replied on at Permalink Reply
jordanlev
Dutchwave replied on at Permalink Reply
Dutchwave
That was an useful thread! It did the trick.
marcsublet replied on at Permalink Reply
marcsublet
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.

<?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();


Regards,
marc