简体   繁体   中英

Printing nodes field value

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM