开发者

Extrafields Visibility. K2 Extension

So i have this code changed in ../html/com_k2/template/default/item.php:

    <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
      <!-- Item extra fields -->
      <div class="ite开发者_开发知识库mExtraFields">
          <h3><?php echo JText::_('Additional Info:'); ?></h3>
          <ul>
            <?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php $user =& JFactory::getUser(); ?>
<?php if($extraField->name == "Price" && $user->get('Guest') ==1): ?>

     <?php else: ?>   
                <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
                    <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
                    <span class="itemExtraFieldsValue"><?php echo ($extraField->type=='date')?JHTML::_('date', $extraField->value, JText::_('K2_DATE_FORMAT_LC')):$extraField->value; ?></span>
                </li>
                <?php endif; ?>
            <?php endforeach; ?>
            </ul>
        <div class="clr"></div>
      </div>
      <?php endif; ?>

What I'm trying to achieve is to hide the extrafield on Guest Viewer on the front-page, and that extrafield will only be visible to certain User groups. I already tried changing this line three times:

  • name == "Price" && $user->get('Guest')==1): ?>
  • name == "itemExtraFields" &&$user->get('Guest') ==1): ?>
  • name == "itemExtraFieldsValue" &&$user->get('Guest') ==1): ?>

(I named my custom field as Price)

So i don't know if I'm missing something on the code or i got the itemFields name wrong. Any help would be appreciated a ton. I already asked in the k2 forum and joomla forum but no one is answering.


Try this code. It is working fine.

<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
        <?php if($extraField->name === "Price" && $this->user->guest){}
            else{ ?>
            <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
                <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
                <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
            </li>
        <?php }?>
<?php endforeach; ?>

I just added a strict comparison to the name and brackets for the if else condition. Also altered the way of checking guest user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜