function bg_image_get_image_path_from_node in Background Images 6
Same name and namespace in other branches
- 7 bg_image.module \bg_image_get_image_path_from_node()
Determines the path of an image on the configured image field on a node and returns it.
Parameters
$nid: The nid of the node to check for an image
$build_url: Optional parameter to return the full URL of the image rather than just the uri
Return value
The path of the image if the node has it, or FALSE.
1 call to bg_image_get_image_path_from_node()
- bg_image_add_background_image_from_node in ./
bg_image.module - Adds a background image to the page using an image from a node. The node must have an image (or media) field and the field must be configured on the bg_image configuration page for this to work.
File
- ./
bg_image.module, line 450 - Allows for customizable background images per page
Code
function bg_image_get_image_path_from_node($nid, $build_url = TRUE) {
$fields = content_fields(NULL, $node->type);
$field_name = variable_get('bg_image_node_field', '');
$node = node_load($nid);
$image_path = FALSE;
if ($node && $field_name) {
if (isset($fields[$field_name]) && $fields[$field_name]['widget']['module'] == 'imagefield') {
if ($node->{$field_name}) {
$image_path = $node->{$field_name}[0]['filepath'];
}
}
}
if ($image_path && $build_url) {
$image_path = file_create_url($image_path);
}
return $image_path;
}