Hi All!

I'm pretty new here and so excited to all the possibilities.

I've done an extensive search and cannot find the answer to this:

My site is a film news site and would like the certain profile fields on the user's article / story submission at the bottom of the article.

I've tried contemplate adding ie.

<?php if($user->profile_experience): ?>
<div class="fields"><?php print check_markup($user->profile_experience) ?></div>
<?php endif ?>

but it does not show up on the article.

Please, how would I go about that .. any direction would be most appreciated.

All the best,
Lilian

Comments

panis’s picture

can you edit your theme node.tpl.php file? If so then you could use the code above after doing a and insert it in the appropriate place after the page or story.

$user = user_load($node->uid);

Your problem above may be that the $user field may not be available to the contemplate engine - try output placeholders to see if contemplate is working and then take it to the next step - you may have to load the user to get access to the profile_experience. Also by default if you have access to a $user - it may be the current logged in user and not the story's author.

liliplanet’s picture

Dear Panis,

Thank you so much for your reply. Panis, I've tried adding :

<?php if($user->office_introduction): ?>
<div class="fields"><?php print check_markup($user->office_introduction) ?></div>
<?php endif ?>

to the node.tpl.php, and still no joy there.

when I add $user = user_load($node->uid); I receive errors.

Another question .. if we do add the profile field into the node.tpl, surely it will then show on the teaser as well?

I found the following :

<?php
if ($page == 0): //if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
endif;
if ($page == 1): //if node is being displayed as a full node
//Anything here will show up when viewing only your post
endif;
?>

would that be of any help?

Look so forward to any reply.

Sincere regards,
Lilian

nevets’s picture

The call to user_load should look like

$account = user_load(array('uid' => $node->nid)):

I also strongly recommend not using $user as a variable name unless you are using it to refer to the current user (in which case it needs to be declared global).

liliplanet’s picture

Thank you Nevets,

This would be fabulous .. if I knew where to put the code as quite confused here now.

Do I add it to node.tpl.php or the the contemplate section (which currently has a major bug and have to wait for a new version).

Sorry, quite new to Drupal, so at a loss on where to add the code to make the specific profile field appear at the bottom of a news (story) article.

So please Nevets, where do I add (step by step please):

$account = user_load(array('uid' => $node->nid)):

and the

if($user->profile_experience):

print check_markup($user->profile_experience)

endif

and just maybe would it be possible to include the user photo on the left of the experience field?

Thank you so much!
Lilian

nevets’s picture

This should work in eiither place though you will need to use $account->profile_experience. So the first part

<?php
$account = user_load(array('uid' => $node->nid)):
?>

should go at the top of the template (that way if you want to use another field in $account you do not need to worry if it has been loadedor not).

The second part can be coded as

<?php
if($account->profile_experience) {
  print check_markup($account->profile_experience) ;
}
?>

If there is no html in between and once again in either template goes where you want the information printed.

If you only want this for news (story) and go the node.tpl.php route I would suggest copying node.tpl.php to node-story.tph.php and modifying node-story.tph.php if that is the only place you want the extra information.

As for the picture that may already be handled by the existing node.tpl.php, look for something like

<?php print $picture ?>
liliplanet’s picture

Dear Nevets,

Thank you kindly for your input .. I'm definitely in the right direction, but currently with the code below it shows somebody else's information, not the person that submitted the press release.

The following is in node.tpl.php

<?php
$account = user_load(array('uid' => $node->nid))
?>

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clear-block">


<?php print $picture ?>

<?php if ($page == 0): ?>
  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>

  <div class="meta">
  <?php if ($submitted): ?>
    <span class="submitted"><?php print $submitted ?></span>
  <?php endif; ?>

  <?php if ($terms): ?>
    <span class="terms"><?php print $terms ?></span>
  <?php endif;?>
  </div>

  <div class="content">
    
    <?php print $content ?>
  </div>

<?php
if ($page == 0): //if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
endif;
if ($page == 1): //if node is being displayed as a full node
//Anything here will show up when viewing only your post
?><?php print $picture ?><div class="fields">Name: <?php print check_plain($account->profile_fname) ;?> <?php print check_plain($account->profile_lname) ;?></div>
<div class="fields">Occupation: <?php print check_plain($account->profile_occupation) ;?></div>
<div class="fields">Telephone: <?php print check_plain($account->profile_telephone) ;?></div>
<div class="fields">Company: <?php print check_plain($account->profile_company) ;?></div>
<div class="fields">City: <?php print check_plain($account->profile_city) ;?></div><?endif;
?> 
<?php
  if ($links) {
    print $links;
  }
?>

</div>

The : in

<?php
$account = user_load(array('uid' => $node->nid)):
?>

gives me an error, so I took it out .. is that perhaps why it does not work?

So close, and yet so far ..

Thank you so much Nevets for any help.

Lilian

PS. How do you receive an email whenever there is a reply on the forum? I do not seem to receive anything.

All the best.

nevets’s picture

Instead of

<?php
$account = user_load(array('uid' => $node->nid))
?>

please try

$account = user_load(array('uid' => $node->uid))

liliplanet’s picture

Yes! it works fabulously! thank you so much Nevets.

You have been so kind, but if you have a moment .. how would I hide 'Admin' or User 1, as I will be putting up most of the press releases. It would be too much have the profile fields of Admin below every article.

Most appreciated!

Lilian

Muslim guy’s picture

I was thinking - why not just use the `Author information' block which you can put at the bottom block? U can pick which profile field along with user picture to appear also

nevets’s picture

Find the line

if ($page == 1):

and change to

if ($page == 1 && $account->uid != 1):

which means the information will only show when viewing a node on a page by itself and when when the nodes author is not user 1.

liliplanet’s picture

Nevets, thank you so much! Works perfectly. You are a super star!