如何以编程方式创建菜单项,同时创建节点? [英] how to programmatically create menu items while creating nodes?

查看:100
本文介绍了如何以编程方式创建菜单项,同时创建节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一些节点编程,这样的:

I'm creating some nodes programmatically, thus:

foreach ($titles as $t) {
    $n = new stdClass();
    $n->type = 'myType';
    $n->uid = 1;
    $n->title = $t;
    $menu = array();
    $menu['link_title'] = $t;
    $menu['menu_name'] = 'primary-links';
    // this attempt at placing the menu item in a particular place in the 
    // menu hierarchy didn't work:
    $menu['parent'] = 'primary-links:867';
    $menu['depth'] = 3;
    $menu['p1'] = '580';
    $menu['p2'] = '867';
    $n->menu = $menu;
    node_save($n);
}

我有一个菜单结构是这样的:

I've got a menu structure like this:

primary-links
    Parent 1
        Child 1
        Child 2
    Parent 2
        Child 3

我希望新的菜单项显示为子3的儿童我能够在同一时间作为节点创建菜单项,它们出现在正确的菜单,而不是在层次结构中的正确位置。我缺少什么?

I want the new menu items to appear as children of Child 3. I was able to create menu items at the same time as the nodes, and they appeared in the correct menu, but not in the correct place in the hierarchy. What am I missing?

推荐答案

我觉得你在复杂的。在当我编程方式创建菜单项节点的过去,我刚才设置的MENU_NAME,LINK_TITLE和腰椎间盘突出症(父链接ID),即:

I think your over complicating it. In the past when I've programmatically created menu items for nodes, I just set the menu_name, link_title, and plid (parent link id), ie:

$menu['link_title'] = $t;
$menu['menu_name'] = 'primary-links';
$menu['plid'] = 867;

菜单模块在某些时候在通话过程中接管到node_save并没有休息为您服务。

The menu module takes over at some point during the call to node_save and does the rest for you.

〜马特

这篇关于如何以编程方式创建菜单项,同时创建节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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