A
A
Alex2017-06-16 21:18:26
1C-Bitrix
Alex, 2017-06-16 21:18:26

How to display every even element of the infoblock array?

Good afternoon, in fact, we have a standard array enumeration in news.list

<?foreach($arResult["ITEMS"] as $arItem):?>
  <?
  $this->AddEditAction($arItem['ID'], $arItem['EDIT_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_EDIT"));
  $this->AddDeleteAction($arItem['ID'], $arItem['DELETE_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
  ?>
  <p class="news-item" id="<?=$this->GetEditAreaId($arItem['ID']);?>">
    <?if($arParams["DISPLAY_PICTURE"]!="N" && is_array($arItem["PREVIEW_PICTURE"])):?>
      <?if(!$arParams["HIDE_LINK_WHEN_NO_DETAIL"] || ($arItem["DETAIL_TEXT"] && $arResult["USER_HAVE_ACCESS"])):?>
        <a href="<?=$arItem["DETAIL_PAGE_URL"]?>"><img
            class="preview_picture"
            border="0"
            src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>"
            width="<?=$arItem["PREVIEW_PICTURE"]["WIDTH"]?>"
            height="<?=$arItem["PREVIEW_PICTURE"]["HEIGHT"]?>"
            alt="<?=$arItem["PREVIEW_PICTURE"]["ALT"]?>"
            title="<?=$arItem["PREVIEW_PICTURE"]["TITLE"]?>"
            style="float:left"
            /></a>
      <?else:?>
        <img
          class="preview_picture"
          border="0"
          src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>"
          width="<?=$arItem["PREVIEW_PICTURE"]["WIDTH"]?>"
          height="<?=$arItem["PREVIEW_PICTURE"]["HEIGHT"]?>"
          alt="<?=$arItem["PREVIEW_PICTURE"]["ALT"]?>"
          title="<?=$arItem["PREVIEW_PICTURE"]["TITLE"]?>"
          style="float:left"
          />
      <?endif;?>
    <?endif?>
    <?if($arParams["DISPLAY_DATE"]!="N" && $arItem["DISPLAY_ACTIVE_FROM"]):?>
      <span class="news-date-time"><?echo $arItem["DISPLAY_ACTIVE_FROM"]?></span>
    <?endif?>
    <?if($arParams["DISPLAY_NAME"]!="N" && $arItem["NAME"]):?>
      <?if(!$arParams["HIDE_LINK_WHEN_NO_DETAIL"] || ($arItem["DETAIL_TEXT"] && $arResult["USER_HAVE_ACCESS"])):?>
        <a href="<?echo $arItem["DETAIL_PAGE_URL"]?>"><b><?echo $arItem["NAME"]?></b></a><br />
      <?else:?>
        <b><?echo $arItem["NAME"]?></b><br />
      <?endif;?>
    <?endif;?>
    <?if($arParams["DISPLAY_PREVIEW_TEXT"]!="N" && $arItem["PREVIEW_TEXT"]):?>
      <?echo $arItem["PREVIEW_TEXT"];?>
    <?endif;?>
    <?if($arParams["DISPLAY_PICTURE"]!="N" && is_array($arItem["PREVIEW_PICTURE"])):?>
      <div style="clear:both"></div>
    <?endif?>
    <?foreach($arItem["FIELDS"] as $code=>$value):?>
      <small>
      <?=GetMessage("IBLOCK_FIELD_".$code)?>:&nbsp;<?=$value;?>
      </small><br />
    <?endforeach;?>
    <?foreach($arItem["DISPLAY_PROPERTIES"] as $pid=>$arProperty):?>
      <small>
      <?=$arProperty["NAME"]?>:&nbsp;
      <?if(is_array($arProperty["DISPLAY_VALUE"])):?>
        <?=implode("&nbsp;/&nbsp;", $arProperty["DISPLAY_VALUE"]);?>
      <?else:?>
        <?=$arProperty["DISPLAY_VALUE"];?>
      <?endif?>
      </small><br />
    <?endforeach;?>
  </p>
<?endforeach;?>

How to set a condition for each even element and change the layout. Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Inav, 2017-06-16
@astrodeep

<? foreach ($arResult["ITEMS"] as $i => $arItem): ?>
    // ...
    <? if ($i % 2 == 0): ?>
        // четный 
    <? else: ?>
        // не четный
    <? endif; ?>
    // ...
<? endforeach; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question