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

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

问题描述

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



谢谢!

解决方案

应该很简单:

  $ url = $ node - > field_name_of_field [$节点 - >语言] [0] [ 'URL']; 

我会打破一点:



字段是节点对象的成员,并且始终以 field _ 为前缀,因此可以找到一个名为 my_field 的字段使用 $ node-> field_my_field



节点对象的每个字段成员本身都是所有不同的数组语言版本的字段,由语言键键入。要访问节点所使用的语言的字段值,请执行以下操作: $ node-> field_my_field [$ node-> language] 或可能 $ node-> field_my_field [LANGUAGE_NONE] (这是默认值)。



此外,每个语言数组都可以如果字段的基数大于1,则有多个字段值。如果您有一个允许多个值的字段(例如图像),则可以按以下方式运行:



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

}

语言数组的每个项目都是实际的字段值。字段可能有多个列(例如,链接模块具有 url 标题属性)。要继续上一个例子,你会发现这样的URL和标题:

  $ url = $ node-> field_name_of_field [ $节点 - >语言] [0] [ 'URL']; 
$ title = $ node-> field_name_of_field [$ node-> language] [0] ['title'];

希望有帮助!


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 ?

Thanks!

解决方案

It should be as easy as:

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

I'll break that down a bit:

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.

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).

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) {

}

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'];

Hope that helps!

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

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