In the teaser, I would like the domain name of the URL to be displayed in plain text.

If a user adds the following link to my site:
http://www.youtube.com/watch?v=4R60P_KeA44

I would like to display:
Site: www.youtube.com

CommentFileSizeAuthor
#5 link-472766-display_domain_only.patch3.21 KBmstrelan

Comments

phdhiren’s picture

Status: Active » Fixed
philbar’s picture

Thanks, I got it figured out using contemplate

Here is the code I used:

<a href="<?php print $node->field_link[0]['url'] ?>"><?php
$shorturl = parse_url($node->field_link[0]['display_url'], PHP_URL_HOST);
echo str_replace('www.', '', $shorturl);    // Ignore sub-domains
?></a>

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

didox’s picture

How can I use this code in views on drupal 7 ?

mstrelan’s picture

Version: master » 7.x-1.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new3.21 KB

Here is a patch which provides a "Domain, as link" formatter for link fields in Drupal 7. It also provides a formatter settings to strip www. from the display.

jcfiala’s picture

Status: Needs review » Fixed

That works nicely. I've added it to 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.