At the moment, I'm using the following code in a tpl.php file:

   <?php
    if ($children[1]) {;
    print "<fieldset class=' collapsible collapsed' style='background-color:#FFFFF2 '><legend><b>Personal Profile</b></legend>";
    print node_view($children[1]);
    print "</fieldset>";
	} elseif ($user->uid == $node->uid) {
    print "<fieldset class=' collapsible collapsed' style='background-color:#FFFFF2 '><legend><b>Personal Profile</b></legend>";
	print "<div align='right'><font size='-2'><a href='/my_profile/personal_details?destination=user'>Create your Personal Profile</a></font></div>";
    print "</fieldset>";
	}
   ?>

...

      <?php
	  if ($children[0]) {
      print "<fieldset class=' collapsible collapsed' style='background-color:#FFFFF2 '><legend><b>Contact Profile</b></legend>";
      print node_view($children[0]);
	  print "</fieldset>";
      } elseif ($user->uid == $node->uid) {
      print "<fieldset class=' collapsible collapsed' style='background-color:#FFFFF2 '><legend><b>Contact Profile</b></legend>";
      print "<div align='right'><font size='-2'><a href='/my_profile/contact_details?destination=user'>Create your Contact Profile</a></font></div>";
	  print "</fieldset>";
	  }
	  ?>

The problem that I've just come to realise (ahem!) is that child 0 is not always the users Contact Profile and child 1 is not always the Personal Profile because it depends on the order in which they were created. Is it possible to write code to determine what child 0 is so that in the legend, I can write the appropriate heading?

Regards

Patrick

Comments

fago’s picture

Status: Active » Fixed

yeah, you can use nodefamily_relation_load_by_type($nid) instead.

e.g.

<code>
$children = nodefamily_relation_load_by_type($nid);

if (isset($children['your_content_type'])) {
  foreach ($children['your_content_type']) as $childnode)
    print node_view($childnode);
}

Patrick Nelson’s picture

Sorry for being a thicko, but what goes in 'your_content_type'? I've tried putting in the name of the content type (it's a CCK), e.g., content_profile but that doesn't seem to work. Or am I missing something?

Regards

Patrick

fago’s picture

yep, that looks right and should work so - of course as long as there is a child node of this type.

Have a look at the output of "print_r($children);" to see how the array is built.

Patrick Nelson’s picture

fago,

It's OK - there was a slight typo in the code above, it should read:

$children = nodefamily_relation_load_by_type($nid);

if (isset($children['your_content_type'])) {
  foreach ($children['your_content_type'] as $childnode)
    print node_view($childnode);
}

(no closing bracket after 'your_content_type'] on the foreach line)

Thanks for all your help - works a treat now.

Regards

Patrick

fago’s picture

ah yes, great that it works now.

Anonymous’s picture

Status: Fixed » Closed (fixed)