Keyword

Hiding specific extra fields from public

  • robb rich
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 1 month ago #101838 by robb rich
Hiding specific extra fields from public was created by robb rich
Hello,
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.

More
12 years 1 month ago #101839 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
a combination of

?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
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 1 month ago #101840 by robb rich
Replied by robb rich on topic Re: Hiding specific extra fields from public
william
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.

More
12 years 1 month ago #101841 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
I dont know, but i wouldnt think so, as the search routine is different. Just have to test it when you get it hidden

Please Log in or Create an account to join the conversation.

  • robb rich
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
12 years 1 month ago #101842 by robb rich
Replied by robb rich on topic Re: Hiding specific extra fields from public
Thanks! That really helped.

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.

More
11 years 11 months ago #101843 by Steven Johnson
Replied by Steven Johnson on topic Re: Hiding specific extra fields from public
Thanks for this thread, I think it was exactly what I needed.

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
  • robb rich's Avatar Topic Author
  • Offline
  • New Member
More
11 years 11 months ago #101844 by robb rich
Replied by robb rich on topic Re: Hiding specific extra fields from public
steven
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.

More
11 years 11 months ago #101845 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
Could I change php to show a video to group1 and a different video to group2?

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.

More
11 years 11 months ago #101846 by szecska
Replied by szecska on topic Re: Hiding specific extra fields from public
Hi!

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.

More
11 years 11 months ago #101847 by william white
Replied by william white on topic Re: Hiding specific extra fields from public
If you want to hide an extra field in the item view then use item.php in your k2 template folder of edit item.php in yoru k2 custom override folder(best solution)

Please Log in or Create an account to join the conversation.