How to make page list ignore the latest article
Permalink
Hi,
I'm looking for a way to make the first item of my page list to appear differently.
This is easy using the built-in $isFirst variable.
However, it targets the first element of each page whereas I would like to target the first element globally.
Alternatively (actually I would prefer this method), I would like my page_list to display every page except the newest. Again, I would like to apply this condition globally and not on a per-page basis.
I am attaching my code below, minus the pagination part, which is the default one.
I'm looking for a way to make the first item of my page list to appear differently.
This is easy using the built-in $isFirst variable.
However, it targets the first element of each page whereas I would like to target the first element globally.
Alternatively (actually I would prefer this method), I would like my page_list to display every page except the newest. Again, I would like to apply this condition globally and not on a per-page basis.
I am attaching my code below, minus the pagination part, which is the default one.
<?php defined('C5_EXECUTE') or die("Access Denied."); $textHelper = Loader::helper("text"); $imgHelper = Loader::Helper('image'); // now that we're in the specialized content file for this block type, // we'll include this block type's class, and pass the block to it, and get // the content $isFirst = true; if (count($cArray) > 0) { ?> <?php for ($i = 0; $i < count($cArray); $i++ ) { $cobj = $cArray[$i]; $target = $cobj->getAttribute('nav_target'); $title = $cobj->getCollectionName(); $date = $cobj->getCollectionDatePublic('M j, Y');
Viewing 15 lines of 46 lines. View entire code block.
Ok, I dropped $isFirst completely and found out a very simple solution.
After I count the results which pagelist returns, I get the latest child page's id like so:
After that, inside the for cycle, I just skip it:
So in the end my code looks like this:
Finally, I just created another block to display my latest article and I'm good to go.
After I count the results which pagelist returns, I get the latest child page's id like so:
After that, inside the for cycle, I just skip it:
if ($childId == $latestId) { continue; }
So in the end my code looks like this:
<?php defined('C5_EXECUTE') or die("Access Denied."); $textHelper = Loader::helper("text"); $imgHelper = Loader::Helper('image'); // now that we're in the specialized content file for this block type, // we'll include this block type's class, and pass the block to it, and get // the content if (count($cArray) > 0) { $getLatest = Page::getByID(1)->getCollectionChildrenArray(1); $latestId = end($getLatest); ?> <?php for ($i = 0; $i < count($cArray); $i++ ) { $cobj = $cArray[$i]; $target = $cobj->getAttribute('nav_target');
Viewing 15 lines of 40 lines. View entire code block.
Finally, I just created another block to display my latest article and I'm good to go.
If I find a way to use it, I can check if it returns something. If yes, $isFirst = true, otherwise set it to false.
Ideas, anyone?