You are here

向导航区块中添加一个链接

g089h515r806 的头像
Submitted by g089h515r806 on 星期日, 2009-08-02 14:22

老葛的Drupal培训班 Think in Drupal

我们把我们的菜单项的类型声明为了MENU_CALLBACK。通过将该类型改为MENU_NORMAL_ITEM,这样就不再将路径简单的映射到一个回调函数上了,而是让Drupal把它作为一个菜单包含进来。
 
提示 因为MENU_NORMAL_ITEM是Drupal的默认菜单类型,所以在本节中的代码里,type键可被忽略。我将会在后面的例子中忽略它。
 
function menufun_menu() {
    $items['menufun'] = array(
        'title' => 'Greeting',
        'page callback' => 'menufun_hello',
        'page arguments' => array('Jane', 'Doe'),
        'access callback' => TRUE,
       'type' => MENU_NORMAL_ITEM,
    );
 
    return $items;
}
 
    菜单项现在显示在了导航区块中,如图4-7所示。
4-7.菜单项显示在了导航区块中
 
If we don’t like where it is placed, we can move it down by increasing its weight. Weight is another key in the menu item definition:
如果我们觉得它放的不是地方,通过增加它的重量,我们还可以将它往下移动。重量是菜单项定义中的另一个键:
 
function menufun_menu() {
    $items['menufun'] = array(
        'title' => 'Greeting',
        'page callback' => 'menufun_hello',
        'page arguments' => array('Jane', 'Doe'),
        'access callback' => TRUE,
       'weight' => 5,
    );
 
    return $items;
}
The effect of our weight increase is shown in Figure 4-8. Menu items can also be relocated without changing code by using the menu administration tools, located at Administer ä Site building äMenus (the menu module must be enabled for these tools to appear).
我们的重量增加后的效果,如图4-8所示。在管理界面“管理➤站点构建 ➤菜单”中(你需要启用菜单模块),使用菜单管理工具,不需要修改代码,也可以调整菜单项之间的相对顺序。
 
4-8.菜单项的重量越大,在导航区块中的位置就越往下。
 

Drupal版本: