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?
基础教程推荐
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01