`
wodamazi
  • 浏览: 1417538 次
文章分类
社区版块
存档分类
最新评论

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'];
?>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics