2011-02-12 147 views
0

我有一個cck節點類型,其中包含對節點庫類型的節點引用。因爲我不想爲我的CCK節點創建一個新的畫廊,所以我想做一下。在顯示cck節點的頁面中;Drupal使用PHP代碼添加「添加新鏈接」

如果給定節點存在圖庫參考,則顯示指向該圖庫的鏈接。如果沒有畫廊存在,我想顯示一個鏈接「添加畫廊」,理想情況下,這將以編程方式創建一個新的畫廊節點和參考。我還想自動填充標題以及作者信息(無需授予用戶訪問權限)。我查看了所有的drupal.org,試圖找到信息,但無法弄清楚。

感謝

回答

0
<?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']; 
+0

我認爲這是完全合理的感謝!我實際上使用面板(3)來顯示cck節點。我可以在可見性規則中過濾PHP代碼,這是我將它放置的位置(而不是創建和編輯模板)。我對如何獲得$ some_nid有點困惑......顯然它取決於cck節點會有所不同。如果我調用node_load()它會加載當前節點嗎? – user379468 2011-02-12 22:49:00