场外可见性。 K2 延伸

发布于 2024-12-05 04:13:50 字数 1895 浏览 1 评论 0原文

所以我在 ../html/com_k2/template/default/item.php 中更改了此代码:

    <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
      <!-- Item extra fields -->
      <div class="itemExtraFields">
          <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; ?>

我想要实现的是隐藏前面的来宾查看器上的额外字段-page,并且该额外字段仅对某些用户组可见。我已经尝试更改此行三次:

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

(我将自定义字段命名为“价格”)

所以我不知道代码中是否遗漏了某些内容,或者 itemFields 名称错误。任何帮助将不胜感激。我已经在k2论坛和joomla论坛问过,但没有人回答。

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="itemExtraFields">
          <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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤还要旧人安 2024-12-12 04:13:50

试试这个代码。它运行良好。

<?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; ?>

我刚刚向名称添加了严格比较,并为 if else 条件添加了括号。还改变了检查访客用户的方式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文