Extract URL from link field in Drupal?(从 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_field找到名为
my_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) {
}
语言数组的每个项目中都是实际的字段值.字段可能有多个列(例如链接模块有 url
、title
和 attributes
).要继续前面的示例,您会找到如下所示的 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Drupal 的链接字段中提取 URL?


基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01