【问题标题】:Drupal adding "add new" link using PHP codeDrupal 使用 PHP 代码添加“添加新”链接
【发布时间】:2011-02-12 20:58:32
【问题描述】:

我有一个 cck 节点类型,其中包含对节点库类型的节点引用。由于我不想真正为我拥有的 CCK 节点创建一个新画廊,所以我想休息一下。在显示cck节点的页面中;

如果给定节点的库引用存在,则显示指向该库的链接。如果不存在画廊,我想显示一个链接“添加画廊”,理想情况下,这将以编程方式创建一个新的画廊节点和引用。我还想自动填充标题以及作者信息(不授予用户访问权限)。我查看了整个 drupal.org 以尝试查找信息,但无法弄清楚。

谢谢

【问题讨论】:

    标签: php drupal cck add


    【解决方案1】:
     <?php
        $node_A = node_load($some_nid);
        if(empty($node_A->field_type_gallery_node_ref[]['nid'] )// imp point this field is an array
        {
        //link to add gallery page
        //call a function for creating a node of gallery and return the nide and you can pass  //parameters like nid of A etc..then return the new node from the function
    $node_GALLERY =  get_gallery_node_new($node_A->nid);
    $node_type_A->field_type_GALLERY_node_ref[]['nid'] = $node_GALLERY;
    }
        else
        { 
        //display this gallery
        }
        ?>
    

    获取当前节点的nid:

    <?php
    if (arg(0) == 'node' && is_numeric(arg(1))) 
    
    $nodeid = arg(1);
    
    ?>
    

    或使用 CCK A 的任何字段值(您知道)并应用与节点表的连接

    $nid_ref_query ='SELECT nid FROM `content_type_A` cto join node n on cto.nid=n.nid where cto.field_some_field_you_know =' . $something;
    $nid_array = db_fetch_array(db_query($nid_ref_query));
    $nid = $nid_array['nid'];
    

    【讨论】:

    • 我认为这完全有道理谢谢!,我实际上使用面板 (3) 来显示 cck 节点。我可以在可见性规则中传递 PHP 代码,这是我放置它的地方(而不是创建和编辑模板)。我对如何获取 $some_nid 有点困惑......显然,它会因 cck 节点的不同而有所不同。如果我调用 node_load() 它会加载当前节点吗?
    猜你喜欢
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    相关资源
    最近更新 更多