Suppose I have parent pages A1 and B1. A1 has child pages A1.1, A1.2,A1.3 and B1 has child pages B1.1, B1.2. I want to list all the respective child pages on A1 and B1. In every child page I have an image and a title. These 2 information needs to be listed in the form of a teaser on the parent page. I need help in doing this whether by coding or by using views, I don't mind as far as I get the proper results. Thank you
Asked
Active
Viewed 1,560 times
2 Answers
0
You can do this is views by creating a view displaying the fields you require or a teaser. Then add a "Content Nid" contextual filter, in the configeration for this filter under "WHEN THE FILTER VALUE IS NOT AVAILABLE" select "Provide default value" and then "PHP Code" then the code I use is as follows
$children = array();
$current = db_query("select menu_name, mlid from {menu_links} where link_path = :node", array(':node' => $_GET['q']));
$current_info = array();
foreach ($current as $value) {
$current_info[] = $value;
}
if($current_info) {
$result = db_query("select mlid, plid, link_path, link_title from {menu_links} where menu_name=:menu and plid=:mlid and hidden=0 order by weight, link_title", array(':menu' => $current_info[0]->menu_name, ':mlid' => $current_info[0]->mlid));
foreach ($result as $row) {
$children[] = $row;
}
}
$nids = array();
foreach ($children as $value){
if( substr( $value->link_path, 0, 5 ) == 'node/' ){
$nids[] = substr( $value->link_path, 5 );
}
}
return implode('+',$nids);
The last thing to do, under "more" at the bottom of the page sellect "Allow multiple values"

pete80
- 545
- 4
- 13
-
I applied your solution but nothing displays, In fact I used the menu block in my case. Another question is how do you set the child pages to make your solution work? – Moushrat Jun 09 '15 at 12:00
-
Menu block works for the menu but not the images, you could the use Menu Icon https://www.drupal.org/project/menu_icons but you would have to add the icons to the menu rather than the node. – pete80 Jun 09 '15 at 13:15
-
I have just succesfully tested the above on a fresh install of drupal, created some nested menu items in the main menu, created the view described above, outputted the view as a block and added the block to the content region – pete80 Jun 09 '15 at 13:31
-
-
please provide me a login and password so that I can view the admin side how you proceeded. Thank you – Moushrat Jun 10 '15 at 11:18
-
-
Can you show me how to display the sibling pages now please? Suppose we have child 1, child 2 and child 3. If I am on page child 2 I have to display child 1 and 3, if I am on page child 1 I have to see child 2 and 3. The result shall be the same format as you demonstrated for the child examples – Moushrat Jun 10 '15 at 12:10
-
pete80 please reply on this link http://stackoverflow.com/questions/30756463/how-to-display-sibling-pages-except-current-page-in-drupal-7 – Moushrat Jun 10 '15 at 12:33
0
I'm using menu_tree_all_data()
to get whole menu structure and then I'm "manually" crawling menu tree.
Also just after reading the tree, I'm calling menu_tree_add_active_path()
which will add active trail indicator. It's part of menu block module so you'll have to install it and don't forget to add dependencies for menu block in your module.
$tree = menu_tree_all_data($menu);
menu_tree_add_active_path($tree);
-
Can you provide a detailed step by step guide please? I am stuck since many days with this. – Moushrat Jun 10 '15 at 10:51
-
Add that code and after that print_r / var dump $tree to see it's structure. Then iterate trough $tree (branch). – MilanG Jun 10 '15 at 13:46