Page LIst block

Permalink 2 users found helpful
was wondering if any has done a mode to the pagelist block to filter by page attributes?

wizardontherun
 
ScottC replied on at Permalink Reply
ScottC
if ($this->displayFeaturedOnly == 1) {
            $cak = CollectionAttributeKey::getByHandle('is_featured');
            if (is_object($cak)) {
               $pl->filterByIsFeatured(1);
            }


$pl is an instance of page_list model, and that is from concrete5 core code under blocks/page_list/controller

also

if ($row['ctID']) {
            $pl->filterByCollectionTypeID($row['ctID']);
         }
//is another filter
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Just to flesh out ScottC's answer a bit, note that the call to "filterByIsFeatured(1)" can be changed to use your attribute name -- for example, if you have an attribute called "top_rated", you can call "filterByTopRated(1)" (the "1" is the value you want to search for -- if it's a checkbox then "1" means "checked" - but if it's a text attribute, pass in a string there instead of the number 1).

For example, if you had a custom page attribute that's a textbox called "automobile_name", and you wanted to pull up all pages that have "honda" as the automobile name, you could do this:
$pl = new PageList();
$pl->filterByAutomobileName('honda');
$pl->sortByDisplayOrder();
$pages = $pl->getPage();
wizardontherun replied on at Permalink Reply
wizardontherun
Thanks, you both. One more thing i was still looking at was how to also sort by an Attributte. can you pass the sortByDisplayOrder the Attribute field?

Frank
jordanlev replied on at Permalink Reply
jordanlev
Hmm... not sure. I did some searching on the forums and found these 2 posts that might provide a solution:

http://www.concrete5.org/community/forums/usage/can-i-sort-users-by...

http://www.concrete5.org/community/forums/customizing_c5/attribute_...

...not sure if they'll work for your situation, but might be worth a shot.
87up replied on at Permalink Reply
87up
Hello everyone,

I could use some help with this problem too.

I have added a Page Attribute checkbox with a handle called mega_menu.

I would like to make a pagelist template that lists all the pages that have the checkbox Megamenu checked. But i can't figure out what im doing wrong

Here is my code so far:

if ($this->displayFeaturedOnly == 1) {
            $cak = CollectionAttributeKey::getByHandle('is_featured');
            if (is_object($cak)) {
               $pl->filterByMegaMenu(1);
   ?>
    <?php
   if (count($cArray) > 0) { ?>
   <?php 
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $title = $cobj->getCollectionName(); ?>
            <td valign="top">
    <div class="kompetencertextmenu"><?php if($cobj->getAttribute('thumbnail')){ ?>
      <img src="<?php echo $imgHelper->getThumbnail($cobj->getAttribute('thumbnail'), 200, 80)->src ?>" alt="<?php echo $title ?>"/>
        <?php }else{ ?>


Thank you in advance.
wizardontherun replied on at Permalink Reply
wizardontherun
this is what I used on a multi select check box.
should work for single check box also.

for ($i = 0; $i < count($cArray); $i++ ) {
         $cobj = $cArray[$i]; 
         $ProjectGroup = $cobj->getCollectionAttributeValue('ProjectGroup');
         if (preg_match( "/PressurizedBananaAndFruitRipeningRooms/i", $ProjectGroup ))
         {
wizardontherun replied on at Permalink Reply 1 Attachment
wizardontherun
screen show of what I am filtering.
87up replied on at Permalink Reply
87up
Thank you... That worked. :)

I have modified your code to look like this

if ($cobj->getCollectionAttributeValue('mega_menu')):


But i got one problem. I only need a max of two pages to be listed. Is that possible ?
Maybe somehow this line of code could do the job ?
$pl->setItemsPerPage(2)
wizardontherun replied on at Permalink Reply
wizardontherun
encloce it in a for loop to count of 2
87up replied on at Permalink Reply
87up
Hello again,

im facing the same problem again. I need to control the number of pages to be displayed. How would you encloce it in a for loop with a count of 2. ?

Thank you in advance.
jordanlev replied on at Permalink Reply
jordanlev
After this line:
for ($i = 0; $i < count($cArray); $i++ ) {

add this:
if ($i > 1) break;
87up replied on at Permalink Reply
87up
Hello jordanlev,

Thank you for your answer, but it didn't work how it was suppose to.

i got 6 pages total, but i only want 2 of these pages to be displayed. Page number 1 and page number 5.

If i use your code, the for loop will never reach page number 5. Only page number 1 will be displayed, because the loop breaks at the count of two. this is where it gets hard for me to find a solution. do you got a solution for that problem ?

I somehow need a loop that breaks after two resultats that matches my filter.

Thank you in advance.
jordanlev replied on at Permalink Reply
jordanlev
I'm a little confused -- are you filtering the pages by a custom attribute? If so, you should just set that attribute on the pages you want (page 1 and 5 in this case) -- then ONLY those 2 will come up in the list.
If not, well then you *should*! That is what all of the code in this thread is about. Otherwise, if you just show pages 1 and 5, your code is going to fail as soon as you add a new page in there which bumps page 5 down to page 6.

Does that make sense?
87up replied on at Permalink Reply
87up
yes i am filtering the pages by a custom attribute with the handle "projekt".

im coding a site for a friend. Thats why i need to make sure that only 2 pages are being displayed, even if 3 pages out of 6 pages are marked with the attribute.

wouldn't it be possible to make a condition like this:

if forloop count 2 and attribute equals "projekt" then break forloop.

im sorry if this variate too much from the original topic. :)
jordanlev replied on at Permalink Reply
jordanlev
Nothing to be sorry for -- I didn't mean for my last response to sound so angry :)

Anyway, I'm wondering if you can just create another attribute that can only apply to those 2 pages, and you can filter on that instead?

Otherwise, you can do it the way you are suggesting -- just do something like this:
$this_page = $i+1;
$allow_pages = array(1, 5);
if (!in_array($this_page, $allow_pages)) {
    continue;
}

In that "allow_pages" array, put the numbers of the pages you want to display.

-Jordan
87up replied on at Permalink Reply
87up
thank you i will try that. im grateful for your help. very usefull. :)
87up replied on at Permalink Reply
87up
i guess that could work. but a loop inside a loop wouldn't work. ?

edit:

I have edited the design. I don't need a max of to pages to be listed anymore.

couldn't get the for loop to work. The result was deadlock.

But thank you for your help. :)
Mnkras replied on at Permalink Reply
Mnkras
try this ;)

you just changed one line... you didn't change the handle
osu replied on at Permalink Reply
osu
Can you guys clarify where I should be editing this code?

I assume I need to copy this:

/concrete/blocks/page_list/controller.php

to this:

/blocks/page_list/controller.php

And modify around line 86 where it shows this:

if ($this->displayFeaturedOnly == 1) {
                $cak = CollectionAttributeKey::getByHandle('is_featured');
                if (is_object($cak)) {
                    $pl->filterByIsFeatured(1);
                }
            }


And if I edit this, presumably it will change the filter option 'Featured pages only' for page_lists right? If so, presumably I'd need to change the text as well so where would I do that? Is there a way to add more options while keeping the 'Featured pages only' option?

Sorry for so many questions, but I see a lot of potential for this so want to get it right.

Thanks

osu
jordanlev replied on at Permalink Reply
jordanlev
Yes, that is where you change the code. Unfortunately there is no override for the actual edit dialog, so you can't change the label from "Featured Pages Only" to something else -- you just have to inform your users that that actually means something different now.

If it's really important that the label be changed, you can copy the entire block and rename it (you will need to make sure all of the handles and database table names are different), and modify the edit interface as well -- but this is a decent amount of work so depending on how important it is it may or may not be worth it.