Exclude current page from pagelist?

Permalink 3 users found helpful
Is this possible by creating a new template?

Essentially, I want a pagelist that displays all the pages at the same level as the current page, but doesn't list the current page.

Any ideas?


View Replies: View Best Answer
adajad replied on at Permalink Reply
Isn't there a custom attribute you could use? I even think it's called "Exclude from page list"
biscutty replied on at Permalink Reply
Not really, as the page list would appear on all the pages on the same level, so if i set the pages to exclude, then none would show?
somenboll replied on at Permalink Reply
Think you could do something like this, $c is current page collection object:

$list = new PageList();
$list->filter('p1.cID', $c->getCollectionID(), '!=');
$page = $list->getPage();

But I guess you want to use the UI to create the block so then you have to do the exclution in the template, using if ($listItemID != $currentCollectionID) ...
The downside here is the list will consist of 9 or 10 rows.
biscutty replied on at Permalink Reply
Thanks, I dont necessarily need it to be a UI block, although I wondered if there is a way of achieving this using a custom theme, by modifying the view.php?

As there are other setting i use within the ui section.

joseajohnson replied on at Permalink Reply
As far as modifying the stock view.php, you may consider overriding it instead, in order to keep from losing changes on updates; this having been said, however, the modification would begin at line 12:
$c = Page::getCurrentPage();
   $cIDcurrent = $c->getCollectionID(); 
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      if ($cobj->getCollectionID() != $cIDcurrent ){// endif on line 33
// process the page list

Just remember to close off the 'if' statement around what should now be line 33.

When you edit/add your pagelist, under 'Location in Website' choose 'beneath another page,' then select the current page's parent.

Displaying the current page's siblings programmatically (ie. without first selecting the parent) is also possible through a template modification and the use of getCollectionParentID, but probably a smidge more costly in terms of overhead - more so in larger sites.

btw, the 'if' statement in the snippet above is essentially what @somenboll was suggesting in the latter half of the above post.

Hope this helps!
jordanlev replied on at Permalink Best Answer Reply
I agree with @joseajohnson's overall approach, but think there's an even simpler modification to the code you can make.
First, as suggested, copy the default template (so create a new directory on your server at SITEROOT/blocks/page_list/, then copy SITEROOT/concrete/blocks/page_list/view.php to that new directory). Edit the copy of the file (SITEROOT/blocks/page_list/view.php), find this line (should be around line #13):
$cobj = $cArray[$i];

...and directly below that line, add this new line:
if ($cobj->getCollectionID() == Page::getCurrentPage()->getCollectionID()) { continue; } //skip current page

One more little thing -- due to a weird bug in C5, if you do this, you will also want to copy SITEROOT/concrete/blocks/page_list/view.css to SITEROOT/blocks/page_list/view.css (otherwise you'll get 404 errors on the page in Firebug/Web Inspector because it looks for a css file there).

sarah3585 replied on at Permalink Reply
Does this code mod still work for the As i can't find the piece of code you mention in the view.php.
jordanlev replied on at Permalink Reply
The view.php template code was changed in 5.5, so it's different.

You're still looking in the same file (and copying it from and to the same location), but when you modify the code, look for this line (should be around line #11):
<?php foreach ($pages as $page):

...and BELOW it, add this:
if ($page->getCollectionID() == Page::getCurrentPage()->getCollectionID()) { continue; } //skip current page
sarah3585 replied on at Permalink Reply
Great stuff, thank you so much!
zarkokuvalja replied on at Permalink Reply 1 Attachment
Thanks a lot for this.
I used this for a similar but different purpose:

I needed automatic navigation that would insert a description along with the link.
So, I used the Page list - but, that didn't add an HTML class to the currently viewed page so I couldn't style it.

I used your tip to hack together this little functionality.
Code on the same place in view.php as yours:
if ($page->getCollectionID() == Page::getCurrentPage()->getCollectionID()) { $current = "current"; } else{ $current = "";};

and then added this down lower (comment left inside to easily find the bit you need to modify):
/* The HTML from here through "endforeach" is repeated for every item in the list... */ ?>
      <li class="<?php echo $current ?>" class="ccm-page-list-title">
         <a href="<?php  echo $url ?>" target="<?php  echo $target ?>"><?php  echo $title ?><span><?php  echo $description ?></span></a>

So now I can have this (attached image)
drbiskit replied on at Permalink Reply
I know this is an old thread - but can anyone tell me how to do this, but with parent pages as opposed to pages at the same level ...

So I have a bunch of 3rd level pages, with the 2nd level pages in a page list block. I want to remove the current parent page in each case. So I have this:

- Blue
- - Sky
- - Sea
- Yellow
- - Sun
- - Banana
- Orange

If I am looking at 3rd level page e.g. 'Sky', I will only want 'Yellow' and 'Orange' to show in my page list, and not Blue.

Hope that makes sense.

** EDIT ** Started a new thread with this:
misam replied on at Permalink Reply
Thank you so much!
hereNT replied on at Permalink Reply
I would think that doing it in the view (if you are paginating) would be a bad idea. You would end up with one less page on whichever one included the match.
biscutty replied on at Permalink Reply
Thanks Josea and Jordan!
somesayinice replied on at Permalink Reply
Here's another way (newer versions):
$pl = new \Concrete\Core\Page\PageList();
$pl->getQueryObject()->where("(p.cID != $cID)"); //Please note, this needs to be first as it will undo any other filtering you have done.