如何在drupal 7中列出当前父页面的所有子页面? [英] How to list all child pages of current parent page in drupal 7?

查看:195
本文介绍了如何在drupal 7中列出当前父页面的所有子页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有父页面A1和B1。 A1有子页面A1.1,A1.2,A1.3和B1有子页面B1.1,B1.2。我想在A1和B1上列出所有相应的子页面。在每个孩子页面中,我都有一个图像和标题。这两个信息需要在父页面上以预告片的形式列出。我需要帮助,无论是通过编码还是使用意见,我不介意,只要我得到正确的结果。谢谢

解决方案

您可以通过创建显示所需字段或预告片的视图来实现这一点。然后在过滤器值不可用的过滤器的配置中添加内容Nid上下文过滤器,选择提供默认值,然后选择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,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);

最后一件事情,在页面底部的更多sellect允许多个值


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

解决方案

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"

这篇关于如何在drupal 7中列出当前父页面的所有子页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆