简体   繁体   English

如何在 drupal 7 中列出当前父页面的所有子页面?

[英]How to list all child pages of current parent page in drupal 7?

Suppose I have parent pages A1 and B1.假设我有父页面 A1 和 B1。 A1 has child pages A1.1, A1.2,A1.3 and B1 has child pages B1.1, B1.2. A1 有子页面 A1.1、A1.2、A1.3,B1 有子页面 B1.1、B1.2。 I want to list all the respective child pages on A1 and B1.我想列出 A1 和 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谢谢

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然后添加一个“Content Nid”上下文过滤器,在“WHEN THE FILTER VALUE IS NOT AVAILABLE”select“提供默认值”然后“PHP代码”下的这个过滤器的配置中,然后我使用的代码如下

$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"最后要做的事情,在页面底部的“更多”下选择“允许多个值”

I'm using menu_tree_all_data() to get whole menu structure and then I'm "manually" crawling menu tree.我正在使用menu_tree_all_data()来获取整个菜单结构,然后我“手动”爬行菜单树。

Also just after reading the tree, I'm calling menu_tree_add_active_path() which will add active trail indicator.同样在阅读树之后,我正在调用menu_tree_add_active_path()它将添加活动跟踪指示器。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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