By czarphanguye on
How do you print a custom profile value? I'll be adding this to comment.tpl.php
Tried '$location', '$profile->location', "$profileobject->location'. Nada.
How do you print a custom profile value? I'll be adding this to comment.tpl.php
Tried '$location', '$profile->location', "$profileobject->location'. Nada.
Comments
It takes a bit of work
You'll need to get the username or uid from the $comment object, then use that to load the user record with user_load(). The resulting object will have the profile information, including your custom fields. A bit of examination with print_r() will help you understand it.
Thanks for the reply, yet I
Thanks for the reply, yet I have no idea what you just said.
Regards,
Czar
As code
To follow up on yelvington's suggestion, as code this woudl be
How do you figure out when
How do you figure out when you need to do load stuff like 'user_load()' and what the actual command is?
For example, I need to do basically the same thing but for a taxonomy term. I want to be able to display Tags in the teaser. I tried things like $node->taxonomy->name...then realized it's in an array so tried some other stuff like $node->taxonomy[30]['name']. Eventually figured out taxonomy wasn't the array name...problem was I couldn't figure out what the array was called as it wasn't displayed in print_r. Unless I was doing something wrong...which wouldn't be a surprise. Is there an easy way to figure out what variables and what not you need to display certain fields?
Some tips
First off, some of it is just learning since there is no single "solution", that said here are some tips to get you started. A good starting point is the PHPtemplate section of the handbook. In particular check out the *.tpl.php sections which show the standard variables to a given template file. Some are strings, some are objects. You can always use
to see the details of one of the variables. You will wan to replace $variable with the actual variable name (example: $comment for comment.tpl.php).
As for the taxonomy terms, $node->taxonomy holds the terms associated with a given node. $node->taxonomy is an array of taxonomy terms (as objects) and you can access a given element with
$term = $node->taxonomy[30]and a particular element$node->taxonomy[30]->name. You can also loop through the array with something like<?phpforeach (
thanks a lot for this topic, it helps to improve my site too)