Drupal学习笔记(九)CCK Link field

A field which lets you add a complete link to your content types; including URL, title, and optionally a target attribute.

Requires the content module(CCK)in Drupal 6, or the fields module (core) in Drupal 7.

The link module is a one-stop content link "field" type for CCK/field. It provides three fields to an authorized user:

  • URL (textfield)
  • Title (textfield)
  • Open New Window (checkbox)
  • Add rel=nofollow attribute

"Title" and "Open New Window" can be optionally enabled or disabled when setting up the content field.

Link module is not necessary to add links to the navigation or primary menus. Links added to the navigation or primary menu can be done with menu module (part of Drupal core). Visit admin/build/menu on your site to configure menu and navigation links. Use Link module if you need to have users enter in a URL that is relevant to a piece of content being added.

If you were to create a field named 'My New Link', the default display of the link would be:

<div class="field_my_new_link" target="[target_value]"><a href="[URL]">[Title]</a></div>

where items between [] characters would be customized based on the user input.

Installation
  • Drop the entire link module directory into your 'sites/all/modules' folder
  • Enable the module from the Administration area modules page (admin/build/modules)
  • Create or Edit a content-type and add a new field of type link (admin/content/types in D6, admin/structure/types in D7)
Configuration

Configuration is only slightly more complicated than a text field. Titles for links can be made required, optional (default), or left out entirely. If no title is provided, the trimmed version of the complete URL is may be displayed.

The target attribute may be set to _blank, top, or left out completely.

The rel=nofollow attribute prevents the link form being followed by certain search engines. More info atWikipedia.

Data Entry

Link supports both internal and external URLs. URLs are validated on input, here are some examples of data input and the default view of a link:

http://drupal.org => http://drupal.org
drupal.org
=> http://drupal.org
<front>
=> http://drupal.org
node/74971
=> http://drupal.org/project/link

Anchors and query strings may also be used in any of these cases, including:

node/74971/edit?destination=node/74972
<front>#pager

Theming

For Drupal 6 you can find more information on how to theme the output (and all other CCK fields) at theCCK Handbook on Theming Individual Fields

Another popular alternative is usingContent Template Module, which allows you to output links (or other field types) in any variation using PHP code. Almost any formatting desired can be accomplished using one of these two methods.

For Drupal 7, I need a link for one or more pages which describe how to theme the output.

Help

If you have questions or trouble, please post to theissue trackerrather than the forum.

Help, my Query String / Fragment disappeared!

If you're printing out the contents of a link field like such:

<?php
print $node->field_example_link[0]['url'];
?>

you'll only see the basic url. To get the whole url, try this:
<?php
print $node->field_example_link[0]['display_url'];
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值