English 中文(简体)
Drupal使用PHP代码添加“添加新”链接
原标题:Drupal adding "add new" link using PHP code

我有一个cck节点类型,它包含对节点库类型的节点引用。由于我不想为我拥有的CCK节点创建一个新的画廊,所以我想做一些休闲活动。在显示cck节点的页面中;

如果给定节点存在库引用,则显示指向该库的链接。如果不存在图库,我想显示一个链接“添加图库”,理想情况下,这将通过程序创建一个新的图库节点和引用。我还想自动填充标题以及作者信息(不允许用户访问)。我在drupal.org上找了很多信息,但都找不出来。

谢谢

最佳回答
 <?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 ];
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签