How to wrap page list code in DIV's every 4 items? PHP Question
Permalink 1 user found helpfulI'm hacking the Thumbview Template add-on view.php.
At the moment, the markup it generates is like this:
<div class="coda-slider"> <div class="panel-wrapper"> <div class="content_block"> <a href=""><img class="ccm-output-thumbnail" alt="" src="" width="100" height="67" /></a> <h2><a href="">Thing</a></h2> <p></p> </div> </div> <div class="panel-wrapper"> <div class="content_block"> <a href=""><img class="ccm-output-thumbnail" alt="" src="" width="100" height="67" /></a> <h2><a href="">Thing</a></h2> <p></p> </div> </div>
However, I want to wrap every four <div class="panel-wrapper"> div's inside another div called '<div class="panel">'
How can I amend my view.php to achieve that? Copy paste example great but an explanation of what is done would be even better!
<?php if (count($cArray) > 0) { ?> <div class="coda-slider"> <?php for ($i = 0; $i < count($cArray); $i++ ) { $cobj = $cArray[$i]; $title = $cobj->getCollectionName(); $link = $nh->getLinkToCollection($cobj); ?> <div class="panel-wrapper"> <div class="content_block"> <?php $pt = $cobj->getCollectionAttributeValue('page_thumbnail'); if($pt){ echo("<a href=\"$link\">"); $imgHelper->outputThumbnail($pt, 100,100, $title);
Thanks for any help...
Thanks again, Ben
Thanks again - Ben
I wonder if you could point me in the right direction. I want do a similar thing. I want to wrap every 2 pages in two divs.
<div class=""><div class="grid-x grid-padding-x">
<?php if (is_object($thumbnail)) { ?> <div class="cell large-6 medium-6"> <a href="<?php echo h($url) ?>" target="<?php echo h($target) ?>"> <?php $img = Core::make('html/image', array($thumbnail)); $tag = $img->getTag(); $tag->addClass('img-responsive'); echo $tag; ?> </a> <?php } ?> <?php if ($includeEntryText) { ?> <div class="single_project_text">
</div></div>
Hope you can help
Thanks
<?php defined('C5_EXECUTE') or die("Access Denied."); $c = Page::getCurrentPage(); /** @var \Concrete\Core\Utility\Service\Text $th */ $th = Core::make('helper/text'); /** @var \Concrete\Core\Localization\Service\Date $dh */ $dh = Core::make('helper/date'); if ($c->isEditMode() && $controller->isBlockEmpty()) { ?> <div class="ccm-edit-mode-disabled-item"><?php echo t('Empty Page List Block.') ?></div> <?php } else { ?> <div class="ccm-block-page-list-wrapper"> <?php if (isset($pageListTitle) && $pageListTitle) {
Now tested code, so this *should* work.
Further explanation
Here we are going to display the panel div if this is the first loop through the forloop or if the page number is evenly divisible by 4 (as in 4/4 has no remainder and gets the div, where 5/4 has a remainder of 1 and doesn't get the div) On the first loop this is asking what is the remainder of 0/4, the answer is 0 (which means false) So the ! in front of it says if this statement is NOT true (if mod says 0) then display the div.
Here we're closing the div if this page is the fourth in a series ($i+1 - again we're counting from zero, where $i= 3 is the fourth page). Also we're checking to see if this is the last item being displayed. So if you're display a total of 10 items, you'll have two panels with 4 pages each and one panel with 2.
Hope the helps - and works :P