Insert node profile fields on a content type

Events happening in the community are now at Drupal community events on www.drupal.org.
liliplanet's picture

Hi,

Hope this message finds you very well.

I would like to have company information below press releases (content type = 'article'). In my node.tpl I have

<?php
print $node->field_company[0]['value']
?>
, but it only shows up on the profile page and not underneath the article. mmm ..

node.tpl is currently as follows:

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

<?php if ($page == 0): ?>
<?php print $picture ?>
<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 == 1): ?>
<?php
// Set up some variables to make the code easier to read without the confusion of which user is which.
$loggedinuser = $GLOBALS['user'];
$profileuser = user_load(array('uid' => $node->uid));?>

<?php print theme("user_picture",$profileuser); ?><?php print $node->field_company[0]['value'] ?>
<div><?php if ($links) { print $links; }?></div><?endif;?>
</div>

Please, how can I insert nodeprofile information on another content type (not profile) and not to duplicate on the profile pages?

Most appreciate any help and thank you.
Lilian

Comments

update

liliplanet's picture

Got the part where I created node-article.php, but still have:

<?php
// Set up some variables to make the code easier to read without the confusion of which user is which.
$loggedinuser = $GLOBALS['user'];
$profileuser = user_load(array('uid' => $node->uid));?>

<?php print theme("user_picture",$profileuser); ?><div><?php print $node->field_company[0]['value'] ?></div>
<div><?php if ($links) { print $links; }?></div><?endif;?>
</div>

the field_company does not show on my article content type ... presuming I have to load something else in place of = user_load ?

Would most appreciate help and thank you.
Lilian

...

michelle's picture

The only way that's going to work is if "field_company" is on the article node type. It sounds like you need to load the nodeprofile node associated with the UID and reference that.

Michelle


See my Drupal articles and tutorials or come check out the Coulee Region

Thank you Michelle

liliplanet's picture

Thank you Michelle for your reply. Definitely stuck here ... please could you tell me exactly what has to go in there ..

Created node-article.php

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

<?php if ($page == 0): ?>
<?php print $picture ?>
<a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a>
<?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 ?>
<?php if ($page == 1): ?>
<?php
// Set up some variables to make the code easier to read without the confusion of which user is which.
$loggedinuser = $GLOBALS['user'];
$profileuser = user_load(array('uid' => $node->uid));?>

<?php print theme("user_picture",$profileuser); ?><?php print $node->field_company[0]['value'] ?>
<div><?php if ($links) { print $links; }?></div><?endif;?>
</div>

just not having any joy here (nothing shows up) and would most appreciate your help.

Lilian

...

michelle's picture

<?php

// Load the nodeprofile node for the user that is the author of the current node
$nodeprofilenode = nodeprofile_load('NODEPROFILETYPETOLOAD', $node->uid);

// Print the company field from the nodeprofile node
print $nodeprofilenode->field_company[0]['value']
?>

NODEPROFILETYPETOLOAD should be changed to the machine name of the node type you are wanting to load. ('uprofile' or whatever)

Michelle


See my Drupal articles and tutorials or come check out the Coulee Region

wow Michelle!

liliplanet's picture

wow Michelle, thank you so much! works beautifully.

If you have another moment please ... how do I add 2 fields instead of repeating the code as I have done ...

<?php

// Load the nodeprofile node for the user that is the author of the current node
$nodeprofilenode = nodeprofile_load('platinum', $node->uid);

// Print the company field from the nodeprofile node
print $nodeprofilenode->field_companyname[0]['value']

?>
<?php

// Load the nodeprofile node for the user that is the author of the current node
$nodeprofilenode = nodeprofile_load('platinum', $node->uid);

// Print the company field from the nodeprofile node
print $nodeprofilenode->field_introduction[0]['value']

?>

This is wonderful .. thank you Michelle.
Lilian

oops one more question please

liliplanet's picture

Michelle, sorry just one more thing ...

I would like a link from the code (or just below) to go to to the users profile with something like 'read more about 'company'...'

Is that possible please ..?

Lilian

Link

michelle's picture

Thanks for bumping it, dougzilla. I missed this question...

The link would be

<?php
print l('read more about ' . $nodeprofilenode->field_company[0]['value'],'user/' . $nodeprofilenode->uid)
?>

Michelle


See my Drupal articles and tutorials or come check out the Coulee Region

Thank you Michelle

dadderley's picture

I found this via the google. Thank you ever so much. This is exactly what I wanted to accomplish.

Thank you Michelle!

liliplanet's picture

You have taught me so much ... thank you. Now that whole section is complete with your help. Most most appreciated.

Lilian

No problem :)

michelle's picture

Glad to help.

Michelle


See my Drupal articles and tutorials or come check out the Coulee Region

load content profile for the author of the node ..

liliplanet's picture

Oops Michelle, I've moved onto content profile for 6.x ..

with the previous code for nodeprofile:

// Load the nodeprofile node for the user that is the author of the current node
$nodeprofilenode = nodeprofile_load('platinum', $node->uid);

// Print the company field from the nodeprofile node
print $nodeprofilenode->field_companyname[0]['value']

?><?php

// Load the nodeprofile node for the user that is the author of the current node
$nodeprofilenode = nodeprofile_load('platinum', $node->uid);

// Print the company field from the nodeprofile node
print $nodeprofilenode->field_introduction[0]['value']
<?
php endif; ?>

please how can I change it to load content profile?

would so much appreciate your help one more time, and again thank you so much!
Lilian

Not sure

michelle's picture

I think nodeprofile_load needs to change to contentprofile_load but I'm not sure. You could always ask in the content profile issue queue.

Michelle


See my Drupal articles and tutorials or come check out the Coulee Region

hi,

30equals's picture

hi,

bumping this because i have a question which is very related to this issue.

for instance, the code posted by michelle:

// Load the nodeprofile node for the user that is the author of the current node
$nodeprofilenode = nodeprofile_load('platinum', $node->uid);

// Print the company field from the nodeprofile node
print $nodeprofilenode->field_companyname[0]['value']

what i'd like to achieve: i'd like to show a nodeprofile cck field in the topic & comment nodes of the forum.
and i have 5 different content types as nodeprofiles. is it possible to just get that field value based on the user id ?
in stead of loading a specific content type ? or get the content_type according to the uid ?
just wanting to avoid making 5 vars to get the all the possible values from each nodeprofile because you don't know what nodeprofile to query

any help would be appreciated. thanx

as a temp solution i put the

30equals's picture

as a temp solution i put the code in a for loop, and all my content types which i use as profiles in an array..
this is an example for the comments, for topics of course use $node->uid in stead of $comment->uid

  
$profileArray = array("content_type1", "content_type2", "content_type3", "content_type4", "content_type5", "content_type6");
 
   $len = count($profileArray);
  
   for ($i = 0;$i<$len;++$i){
      $nodeprofilenode = nodeprofile_load($profileArray[$i], $comment->uid);
      $currCompany = $nodeprofilenode->field_member_current_company[0]['value'];
        print "<span class=\"currCompany\"><b>".$currCompany."</b></span>";
     
   }

Profiles as nodes

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: