在Drupal 7中获取节点的URL

时间:2021-09-16 16:52:42

Goal: To send an email with a list of URLs generated from nodes.

目标:发送包含从节点生成的URL列表的电子邮件。

In my custom module I have managed to get the node id which the user wants and I now want to get the URL of each node to put into my email.

在我的自定义模块中,我设法获取用户想要的节点ID,现在我想获取每个节点的URL以放入我的电子邮件中。

I searched the db and used google but I can't seem to find the right solution.

我搜索数据库并使用谷歌,但我似乎无法找到正确的解决方案。

It seems we need to construct the URL something like this:

看来我们需要构建这样的URL:

<?php
global $base_url;
$link=$base_url."// few more parameters 

5 个解决方案

#1


83  

You can use the url() function:

你可以使用url()函数:

$options = array('absolute' => TRUE);
$nid = 1; // Node ID
$url = url('node/' . $nid, $options);

That will give you the absolute path (i.e. with http://example.com/ in front of it), with the URL aliased path to the node page.

这将为您提供绝对路径(即前面有http://example.com/),以及节点页面的URL别名路径。

#2


13  

You can also try drupal_lookup_path('alias',"node/".$node->nid).

您也可以尝试drupal_lookup_path('alias',“node /".$ node-> nid)。

#3


7  

Also you can get it by

你也可以得到它

   $path=drupal_get_path_alias('node/'.$nid);

#4


4  

You can also use the l() function.

您也可以使用l()函数。

  l(t('Link text'), 'node/123', array('options' => array('absolute' => TRUE)));

#5


-6  

use

使用

$node_url;

$ node_url;

it will give you the current node url

它会为您提供当前节点的URL

#1


83  

You can use the url() function:

你可以使用url()函数:

$options = array('absolute' => TRUE);
$nid = 1; // Node ID
$url = url('node/' . $nid, $options);

That will give you the absolute path (i.e. with http://example.com/ in front of it), with the URL aliased path to the node page.

这将为您提供绝对路径(即前面有http://example.com/),以及节点页面的URL别名路径。

#2


13  

You can also try drupal_lookup_path('alias',"node/".$node->nid).

您也可以尝试drupal_lookup_path('alias',“node /".$ node-> nid)。

#3


7  

Also you can get it by

你也可以得到它

   $path=drupal_get_path_alias('node/'.$nid);

#4


4  

You can also use the l() function.

您也可以使用l()函数。

  l(t('Link text'), 'node/123', array('options' => array('absolute' => TRUE)));

#5


-6  

use

使用

$node_url;

$ node_url;

it will give you the current node url

它会为您提供当前节点的URL