How to wrap page list code in DIV's every 4 items? PHP Question
Permalink 1 user found helpful
More of a PHP question I suppose but before I hop over to stackoverflow...
I'm hacking the Thumbview Template add-on view.php.
At the moment, the markup it generates is like this:
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!
Thanks for any help...
I'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>
Viewing 15 lines of 37 lines. View entire code block.
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);
Viewing 15 lines of 32 lines. View entire code block.
Thanks for any help...
Fixed previous code typos.
Hi glockops, thanks very much for taking the time here to explain that. I'm going to give it a whirl shortly but more importantly go through your explanation in the hope I can understand it for next time.
Thanks again, Ben
Thanks again, Ben
Just done a quick test and works perfect. Will have a closer look this evening to see how it's doing it's thing!
Thanks again - Ben
Thanks again - Ben
Hi There
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">
</div></div>
Hope you can help
Thanks
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">
Viewing 15 lines of 50 lines. View entire code block.
</div></div>
Hope you can help
Thanks
I have managed to get it to wrap every 2 pages but for some reason it seems to be repeating the page list 6 times. Any help would be appreciated.
<?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) {
Viewing 15 lines of 182 lines. View entire code block.
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