从 Drupal 的链接字段中提取 URL? [英] Extract URL from link field in Drupal?

查看:32
本文介绍了从 Drupal 的链接字段中提取 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 URL 和标题组成的 链接字段,我需要打印出来只有在我的节点内容类型 tpl 文件中没有标题的链接字段的 URL,这可能吗?

I have a link field that is composed from a URL and the title, I need to print out only the URL of the link field without the title in my node content type tpl file, is that possible ?

谢谢!

推荐答案

应该很简单:

$url = $node->field_name_of_field[$node->language][0]['url'];

我会分解一下:

字段是节点对象的成员,总是以 field_ 为前缀,因此可以使用 $node->field_my_fieldmy_field 的字段代码>.

Fields are members of the node object and are always prefixed with field_ so a field called my_field can be found with $node->field_my_field.

节点对象的每个字段成员本身就是该字段的所有不同语言版本的数组,由语言键键控.要访问表示节点的语言的字段值,您将使用:$node->field_my_field[$node->language]$node->field_my_field[LANGUAGE_NONE](这是默认设置).

Each field members of the node object is itself an array of all different language versions for the field, keyed by the language key. To access the field value for the language that the node is denoted as you would use: $node->field_my_field[$node->language] or perhaps $node->field_my_field[LANGUAGE_NONE] (which is the default).

此外,如果字段的基数大于 1,则每个语言数组中可能有多个字段值.如果您有一个允许多个值的字段(例如图像),您将像这样遍历每个值:

Further to that, each language array can potentially have multiple field values in it, if the cardinality of the field is greater than 1. If you have a field (e.g. images) with multiple values allowed you would run through each like this:

foreach ($node->field_my_field[$node->language] as $delta => $item) {

}

语言数组的每个项目中都是实际的字段值.字段可能有多个列(例如链接模块有 urltitleattributes).要继续前面的示例,您会找到如下所示的 url 和标题:

Within each item of the language array are the actual field values. Fields may have multiple columns (for example the link module has url, title and attributes). To continue with the previous example you would find the url and title like this:

$url = $node->field_name_of_field[$node->language][0]['url'];
$title = $node->field_name_of_field[$node->language][0]['title'];

希望有帮助!

这篇关于从 Drupal 的链接字段中提取 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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