I would like to print 开发者_开发问答nodes field value in Drupal 7 PHP block but when i'm using the code:
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
if ($node = node_load(arg(1))) {
if ($node->type == 'offer') {
$company_name = check_plain($node->field_company[0]['value']);
}
}
if (!empty($company_name)) {
print $company_name;
}
}
?>
it does nothing - nothing prints. I'm sure that my variable is empty, but why? What am I doing wrong?
Thanks for any help
$company_name = check_plain($node->field_company[0]['value']);
That's sooo D6. :) In D7, by default it would be:
$company_name = check_plain($node->field_company[$node->language][0]['value']);
Generally, just print_r/var_dump (or kpr/dpr if you have devel installed) $node object there to see what fields you have inside and how to access them.
精彩评论