You need to login to send post. No account yet? Create one:
Create account

How display (show) content of CCK imagefield in PHP

No replies
admin

It is infuriating. When you displaying node, the CCK imagefield is showing image or default image as expected.

The same using Views.

But if you will try use:

  • $my_node = node_load(nid);

$my_node contains no more than image link (if any) and NO DEFAULT image (if defined).

The first step is fortunately easy - you have to rebuild content of node. Drupal has function for it:

  • $my_node = node_build_content($my_node);

As far as good. The default image is back, however still just as a link. Now is time for some elegance. You can find plenty of guides how display image using its link, but if you'll consider its title and alternative name, it is a little too much of code. Lack of elegance. Try next function instead:

  • print theme_imagefield_image($my_node->field_filedname[0]);

And voilá... Your images are back into game in three rows of PHP!