There is a need to output a div in a certain place of the site. For example, after element 6:
Attempts to iterate over the elements of the items array and to output some div to element 7 were unsuccessful:
<?php if(count($this->items)): ?> <div class="tagItemList"> <?php $i = 0; foreach($this->items as $item): if (++$i==7): echo "<div>Мой див</div>"; endif; ?>
A div is either not displayed, or is displayed randomly (that is, $ i does not correspond to the real position in the pattern) Are there any alternative methods for solving the problem?
in pkhp not strong, thanks for the help.
I enclose all the code:
<?php defined('_JEXEC') or die; $doc =& JFactory::getDocument(); $pagdata = $this->pagination->getData(); if($pagdata->next->link){ $doc->addHeadLink( $pagdata->next->link, 'next'); } if($pagdata->previous->link){ $doc->addHeadLink( $pagdata->previous->link, 'prev'); } ?> <!-- Start K2 Tag Layout --> <div id="k2Container" class="tagView<?php if($this->params->get('pageclass_sfx')) echo ' '.$this->params->get('pageclass_sfx'); ?>"> <?php if($this->params->get('show_page_title')): ?> <!-- Page title --> <h1 class="componentheading<?php echo $this->params->get('pageclass_sfx')?>"> <?php echo $this->escape($this->params->get('page_title')); ?> </h1> <?php endif; ?> <?php if(count($this->items)): ?> <div class="tagItemList"> <?php $i = 0; foreach($this->items as $item): if (++$i==7): echo "<div>Мой див</div>"; endif; ?> <!-- Start K2 Item Layout --> <div class="tagItemView"> <div class="tagItemBody"> <?php if($item->params->get('tagItemImage',1) && !empty($item->imageSmall)): ?> <!-- Item Image --> <div class="tagItemImageBlock"> <span class="tagItemImage"> <a href="<?php echo $item->link; ?>" title="<?php if(!empty($item->image_caption)) echo K2HelperUtilities::cleanHtml($item->image_caption); else echo K2HelperUtilities::cleanHtml($item->title); ?>"> <img src="<?php echo $item->imageMedium; ?>" alt="<?php if(!empty($item->image_caption)) echo K2HelperUtilities::cleanHtml($item->image_caption); else echo K2HelperUtilities::cleanHtml($item->title); ?>" style="width:<?php echo $item->params->get('_itemMedium'); ?>px; height:auto;" /> </a> </span> <div class="clr"></div> </div> <?php endif; ?> <div class="tagItemHeader"> <?php if($item->params->get('tagItemDateCreated',1)): ?> <!-- Date created --> <span class="tagItemDateCreated"> <?php echo JHTML::_('date', $item->created , JText::_('K2_DATE_FORMAT_LC2')); ?> </span> <?php endif; ?> <?php if($item->params->get('tagItemTitle',1)): ?> <!-- Item title --> <p class="tag-title-box"> <?php if ($item->params->get('tagItemTitleLinked',1)): ?> <a href="<?php echo $item->link; ?>"> <?php echo $item->title; ?> </a> <?php else: ?> <?php echo $item->title; ?> <?php endif; ?> </p> <?php endif; ?> </div> <div class="introTags"> <!-- Item introTag --> <?php $tags = K2ModelItem::getItemTags($item->id,3); for ($i=0; $i<sizeof($tags); $i++) { $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name)); } $item->tags=$tags; ?> <div class="introTagsBlock"> <?php if(count($item->tags)): ?> <!-- Item tags --> <span class="intro-cool-tags"> <?php $counter = 0; ?> <?php foreach ($item->tags as $tag): ?> <?php if (++$counter > 3) break; ?> <a href="<?php echo $tag->link; ?>">#<?php echo $tag->name; ?></a> <?php endforeach; ?> </span> <?php endif; ?> </div> <?php if($item->params->get('tagItemIntroText',1)): ?> <!-- Item introtext --> <div class="tagItemIntroText"> <?php $text = $item->introtext; $max_lengh = 180; if(mb_strlen($text, "UTF-8") > $max_lengh) { $text_cut = mb_substr($text, 0, $max_lengh, "UTF-8"); $text_explode = explode(" ", $text_cut); unset($text_explode[count($text_explode) - 1]); $text_implode = implode(" ", $text_explode); echo $text_implode."..."; } else { echo $text; } ?> </div> <?php endif; ?> <div class="clr"></div> </div> </div> <div class="clr"></div> <?php if($item->params->get('tagItemExtraFields',0) && count($item->extra_fields)): ?> <!-- Item extra fields --> <div class="tagItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($item->extra_fields as $key=>$extraField): ?> <?php if($extraField->value != ''): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if($extraField->type == 'header'): ?> <h4 class="tagItemExtraFieldsHeader"><?php echo $extraField->name; ?></h4> <?php else: ?> <span class="tagItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="tagItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php endif; ?> </li> <?php endif; ?> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> <?php if($item->params->get('tagItemCategory')): ?> <!-- Item category name --> <div class="tagItemCategory"> <span><?php echo JText::_('K2_PUBLISHED_IN'); ?></span> <a href="<?php echo $item->category->link; ?>"><?php echo $item->category->name; ?></a> </div> <?php endif; ?> <?php if ($item->params->get('tagItemReadMore')): ?> <!-- Item "read more..." link --> <div class="tagItemReadMore"> <a class="k2ReadMore" href="<?php echo $item->link; ?>"> <?php echo JText::_('K2_READ_MORE'); ?> </a> </div> <?php endif; ?> <div class="clr"></div> </div> <!-- End K2 Item Layout --> <?php endforeach; ?> </div> <!-- Pagination --> <div class="k2Pagination"> <p><?php if($this->pagination->getPagesLinks()): ?></p> <?php echo $this->pagination->getPagesLinks(); ?> <div class="clr"></div> <?php/* echo $this->pagination->getPagesCounter();*/ ?> </div> <?php endif; ?> <!--Social--> <script type="text/javascript">(function(w,doc) { if (!w.__utlWdgt ) { w.__utlWdgt = true; var d = doc, s = d.createElement('script'), g = 'getElementsByTagName'; s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true; s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js'; var h=d[g]('body')[0]; h.appendChild(s); }})(window,document); </script> <div data-background-alpha="0.0" data-buttons-color="#ffffff" data-counter-background-color="#ffffff" data-share-counter-size="16" data-top-button="false" data-share-counter-type="common" data-share-style="1" data-mode="share" data-like-text-enable="false" data-hover-effect="rotate-cw" data-mobile-view="true" data-icon-color="#ffffff" data-orientation="fixed-right" data-text-color="#000000" data-share-shape="round-rectangle" data-sn-ids="fb.vk.ps.gp.tw." data-share-size="40" data-background-color="#373737" data-preview-mobile="false" data-mobile-sn-ids="fb.vk.tw.wh.ok.vb." data-pid="1534893" data-counter-background-alpha="1.0" data-following-enable="false" data-exclude-show-more="true" data-selection-enable="true" class="uptolike-buttons" ></div> <?php endif; ?>