- Posts: 14
COMMUNITY FORUM
Hiding specific extra fields from public
- robb rich
-
Topic Author
- Offline
- New Member
I followed a couple of great posts that showed how to break the Extra Fields into individual items, and then call to them by ID to easily customize how they are displayed. The only thing I have run into is I need about 20 of those to be viewable only to registered (administrator) users.
I have some plugins that will hide text from public view, but that only works within the editor. So I am hoping someone knows of a php script I can insert in my K2 item.php to hide the Extra Fields based on the status of the visitor.
Thank you in advance,
Robb
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
?php $user =& JFactory::getUser()
and
if ($user->guest) {
echo "Please log in.";
} else {
echo "Welcome!";
}
can be used to wrap the dispaly code with the appropriate changes
Please Log in or Create an account to join the conversation.
- robb rich
-
Topic Author
- Offline
- New Member
- Posts: 14
thank you for the reply!
so to see if I understand correctly, in my K2 item.php page I would do something like this?
<?php $user =& JFactory::getUser()>
if ($user->guest) {
echo "Please log in.";
} else {
echo
<ul>
<li>
<?php if($extrafieldsid[31]) {?>
<span class="itemExtraFieldsLabel"><?php echo $extrafieldslabels[31];?>: </span><span class="itemExtraFieldsValue"><?php echo $extrafieldsid[31];?></span><br>
<?php }?>
</li>
</ul>
;
}
would that code also hide these items from the search feature for a guest?
I am really close to having this issue resolved...
thanks again
robb
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- robb rich
-
Topic Author
- Offline
- New Member
- Posts: 14
I found the correct combination for the code to hide my entire string of extra fields - now I just need to find a way to get my search to not look at the extra fields. I may have to use a different search component, but thanks to you I am that much closer.
here's what I ended up doing:
<?php $user =& JFactory::getUser(); ?>
<?php if ($user->guest): ?>
<?php else: ?>
<ul>
<li>
<?php if($extrafieldsid[31]) {?>
<span class="itemExtraFieldsLabel"><?php echo $extrafieldslabels[31];?>: </span><span class="itemExtraFieldsValue"><?php echo $extrafieldsid[31];?></span><br>
<?php }?>
</li>
</ul>
<?php endif; ?>
thanks for your help!
robb
Please Log in or Create an account to join the conversation.
- Steven Johnson
-
- Offline
- Senior Member
- Posts: 69
I was hoping to display a content item to any visitor but if that visitor is a logged member they they would see the content item plus some extra fields.
I was thinking this could be my plan
1. Create the content item
2. Add extrafields to the the content item
3. Use this code to only show the extra field to registered users
Log in or Create an account to join the conversation.
- robb rich
-
Topic Author
- Offline
- New Member
- Posts: 14
I would think it's possible. you'd just have to create the two separate groups, and then find the right phrasing to get the group.
probably something similar to this:
if ( $userGroupName == $myGroupName && $myGroupName == 'Group1' )
{
// administrators can't change each other
$lists = '<input type="hidden" name="gid" value="'. $user->get('gid') .'" /><strong>'. JText::_( 'Group1' ) .'</strong>';
}
else
{
$gtree = $acl->get_group_children_tree( null, 'USERS', true);
I'm not 100% certain of the call to make, but I'm pretty sure it can be done with some variation on the code above.
good luck!
rob
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
if you are relying on using the built in k2 media (video) there is only one per item
Please Log in or Create an account to join the conversation.
- szecska
-
- Offline
- New Member
- Posts: 4
I can't find this text. :(
K2 v.2.6.1
Should I find it here?
components\com_k2\templates\default\item.php
Should I edit this?
<ul>
<?php foreach ($this->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; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- szecska
-
- Offline
- New Member
- Posts: 4
I would like to make visible the extra fields only for the registered users.
Would you write down to me what should I change in the item.php file exactly?
Thanks.
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Allow Retistared Users Only -->
<?php $user =& JFactory::getUser(); ?>
<?php if ($user->guest): ?>
guest user cannot see them
<?php else: ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3>
<ul>
<?php foreach ($this->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; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- szecska
-
- Offline
- New Member
- Posts: 4
It' s working.... :)
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- Pablo Benitez
-
- Offline
- New Member
- Posts: 9
Here is the problem:
((int)($extrafield->group)) == 12
If i put <> the condition is met, and in the echo $extraField->group a 12 is print. This doesn't make sense to me but I'm not a php expert. It should be something silly that I'm missing. Please help!
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value): ?>
<!-- Allow Retistared Users Only -->
<?php $user =& JFactory::getUser(); ?>
<?php if ($user->guest): ?>
<?php if(((int)($extrafield->group)) == 12): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel">TEST<?php echo $extraField->group; ?>TEST</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?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->id ?><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?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 "86" ?><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Have you tried using var_dump() to see all the possible values you can use?
Please Log in or Create an account to join the conversation.