开发者

Printing nodes field value

开发者 https://www.devze.com 2023-03-15 14:49 出处:网络
I would like to print 开发者_开发问答nodes field value in Drupal 7 PHP block but when i\'m using the code:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号