Another is_featured question: Include all BUT is_featured

Permalink
Hello everyone,

I am a first time user of Concrete5 and currently working on a lower budget project to try this out. I am thoroughly impressed by C5, the longer i work with it.

Anyway, I can't for the life of me figure out how to have a page list block showing all BUT the "is_featured". Thing is, client wants 2 blocks of page lists on one page, one showing the featured pages and the other all the other pages, thus the one with "is_featured" attribute not checked.

I want to keep this simple and not bother the client with another attribute to check for pages that aren't featured pages.

Any solutions?


btw:

found this in the controller of page list block:

Loader::model('attribute/categories/collection');
         if ($this->displayFeaturedOnly == 1) {
            $cak = CollectionAttributeKey::getByHandle('is_featured');
            if (is_object($cak)) {
               $pl->filterByIsFeatured(1);
            }
         }

waldbach
 
mkly replied on at Permalink Reply
mkly
The magic call filterByIsFeatured() is nice but a little confusing if you want to do more advanced comparisons. This is probably easier to understand.
Loader::model('attribute/categories/collection');
         // You'll have to change this if statement
         if ($this->displayFeaturedOnly == 1) {
            $cak = CollectionAttributeKey::getByHandle('is_featured');
            if (is_object($cak)) {
               // This is with regulat filterByAttribute()
               $pl->filterByAttribute('is_featured', 1, '!=');
               // This is with the magic call
               $pl->filterByIsFeatured(array(1, '!='));
               // don't use both this is just for demostration
            }
         }
waldbach replied on at Permalink Reply
waldbach
Hey, i think that could work. I'll try later today. Thanks a lot mkly!!
waldbach replied on at Permalink Reply
waldbach
mkly, minor changes but this does the job perfectly (bare in mind, just learning php here, so i am not sure if this is efficient or follow the code of conduct of C5)

Loader::model('attribute/categories/collection');
         if ($this->displayFeaturedOnly == 1) {
            $cak = CollectionAttributeKey::getByHandle('is_featured');
            if (is_object($cak)) {
               $pl->filterByIsFeatured(1);
            }
         }
         Loader::model('attribute/categories/collection');
            if ($this->displayFeaturedOnly == 0) {
               $cak = CollectionAttributeKey::getByHandle('is_featured');
               if (is_object($cak)) {
                     // This is with regulat filterByAttribute()
                     $pl->filterByAttribute('is_featured', 1, '!=');
               }
            }
mkly replied on at Permalink Best Answer Reply
mkly
Ya, I was just using you code to demostrate, it wouldn't actually work.
Loader::model('attribute/categories/collection');
$cak = CollectionAttributeKey::getByHandle('is_featured');
if(is_object($cak)) {
  if ($this->displayFeaturedOnly == 1) {
    $pl->filterByIsFeatured(1);
  } else {
    $pl->filterByAttribute('is_featured', 1, '!=');
  }
}

Looks like you are getting the hang of it.
You don't have to load a particular model more than once.
I shuffled a few things around to shorten it up a bit.
Nice job.
waldbach replied on at Permalink Reply
waldbach
Thanks so much! That's perfect.
luan replied on at Permalink Reply
How would you go about doing this if you wanted to feature the content on a home page and a feature list page. For an example, I have two attribute is_featured and is_featured_home. I'm pretty new to php also. And thank you in advance.
waldbach replied on at Permalink Reply
waldbach
not sure what you mean?
you mean you wish to include the homepage content in the featured page list as well?
luan replied on at Permalink Reply
Well let say I can create a page that would allow the user to apply a title description and image. On the home page, I have a gallery slider and to feature five. While on a separate feature page, the user can choose to feature as many as they'd like. And the pieces for the Home feature can be different than the featured page. I was thinking when the user creates the page or product, they check if they'd want it to be is_featured (on the feature page) and/or is_featured_home (featured on the home page). I hope this makes sense and not sure if this relates to the current topics. Thanks for the help.
SkyBlueSofa replied on at Permalink Reply
SkyBlueSofa
I've created an addon called Page List Plus that can do what you are asking, however it may be overkill if this is a small site and you're only looking to use it in one place.

With it, you can filter by almost any attribute based on whether it is true, false, less than, equal to, etc.

Good luck.
waldbach replied on at Permalink Reply
waldbach
Cheers, Skybluesofa! That could be very welcome in the next round, it looks like i will need this often.

I'll check it out, thanks.