Hi,

Please, I would like content to show depending on the author role. For instance if a user is a Platinum member it will show their content, but if their role expired (back to authenticated role), it does not show the field anymore. CCK permissions only give the rights to edit or add info depending on role, but I need the code for the node-profile.tpl.php

It is quite the opposite to the following:

<?php global $user; if (in_array('Platinum Member',$user->roles)) : ?>  
<div class="field field-type-text field-field-introduction">
 <div class="field-items">
      <div class="field-item"><h3><?php print $node->field_introduction[0]['view'] ?></h3></div>
  </div>
</div>

which shows the content to the user if the user (viewer) is a Platinum member.

I want if the author of the content is a Platinum member to show the field and if they have expired to hide the field.

Is that possible please?

Look so forward to any reply.
Lilian

Comments

michelle’s picture

Not tested...

<?php 
$account = user_load(array('uid' => $node->uid));
if (in_array('Platinum Member', $account->roles)) :  
?>

<div class="field field-type-text field-field-introduction">
<div class="field-items">
      <div class="field-item"><h3><?php print $node->field_introduction[0]['view'] ?></h3></div>
  </div>
</div>

<?php endif; ?>

I can't remember if that semi colon is needed on the endif... I don't use that construction much.

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

liliplanet’s picture

Michelle, you are a genius! That is more than stunning .. thank you so much!

Wishing you a fabulous weekend.
Lilian

michelle’s picture

No problem. Just paying it forward. ;)

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

liliplanet’s picture

Hi Michelle,

Actually I was a little too hasty there ...

The content shows 'if the user that posted the content is a Platinum Member' (wonderful), but unfortunately the same content, for instance 'admin's content', shows on every node profile.tpl that is a Platinum Member and does not keep it to only the 'admin's profile'.

<?php
$account = user_load(array('uid' => $node->uid));
if (in_array('Platinum Member', $account->roles)) : 
?>

<div><?php
$listlength="10";
$nodetype="article";
$output = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = '%s' AND n.status = 1 ORDER BY n.created DESC"), $nodetype, 0, $listlength));
print $output;
?></div>
<?php endif; ?>

So close :)

Michelle, how to show only the content on the specific user profile that posted the information and that is only if they are a Platinum Member.

Most appreciate your help and time ..
Lilian

michelle’s picture

I'm not sure if I'm following you, but I _think_ you're asking how to restrict the query to content written by that user? In that case, I think this will do it, but my SQL isn't the best. I tend to use views for everything. ;)

$output = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = '%s' AND n.status = 1 AND n.uid = %d ORDER BY n.created DESC"), $nodetype, $node->uid, 0, $listlength));

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

liliplanet’s picture

Michelle, if I only had your ability ... you're amazing! You have helped me so much.

Yes! it works wonderfully, most appreciated.

Have a great week.
Lilian

michelle’s picture

Ah, good, glad it worked. My "ability" is just plugging away at this and learning all the time. :)

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

liliplanet’s picture

Hi Ken,

Thanx for your reply. cck field permission will not work after the user has posted the information.

Sometimes members expire their role and then I want to remove the information from their profile.

Have a great day.
Lilian

saveyou’s picture

this is complete and tested code

global $user;
$account = user_load(array('uid' => $user->uid));
if (in_array('authenticated user', $account->roles)) :

// execute your code here

endif;