0
votes

At the moment admin can upload background image from the admin to the each page. So basically page node type has a field called background_image and then I get that image place it to div's background image with CSS.

I also have second content type called car_article. These pages are listed under one of those pages nodes. So basically sitemap looks like this:

Cars (node type = page, parent)
-Audi (node type = car_article, child page)
-BMW (node type = car_article, child page)
-Chevrolet (node type = car_article, child page)

Now what I would need to do is get the background image from the parent page, Cars page in this case. So how can I get field content from parent page. And this would need to work always if page is car_article node type, it would automatically try to load background image from parent page.

Thanks!

3
No one knows how to achieve this? - user1069269
I am not clear as to what you are trying to do. Pls provide links and code. - Vishal Khialani

3 Answers

0
votes

I guess you can achieve that by using http://drupal.org/project/menu_node_views.

But it's perhaps overkill...

With http://drupal.org/project/menu_node you can know witch nid the parent menu is pointing on.

For two levels is not very a problem to run on more node_load. What is going to be hard is if you want make it recursive and avoiding loading every node until you find one with an image..

0
votes

Just a suggestion but you could try get access to the top node using arg()

e.g. if your page is
/cars/bmw
and the nodes are structured
/node/care_node/bmw_node

you can use arg(1) to get the id of the car node and then load that into a variable

e.g.

$parentNode = node_load(arg(1));

Now you can use parentNode to access the node of the parent.

If your site is more complex and you have many levels you could do some math to find the current arg and then -1

0
votes

I face a similar problem and here is how I get to the field, but I think it's rather convoluted.

$menuParent = menu_get_active_trail();
reset($menuParent); //point to first
next($menuParent);  //jump next, to skip 'home'
$firstItem = current($menuParent);
$path = drupal_get_normal_path($firstItem['link_path']);
$node = menu_get_object('node', 1, $path);
$field = field_view_field('node', $node, 'background_image');
$sectionBgUrl = file_create_url($field[0]['#item']['uri']);