Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-09-01 05:44:04

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

adi_link – Enhanced links

Summary

adi_link will output links from various sources, with custom attributes.

Once installed and activated, you’ll get a new tag: <txp:adi_link/>.

See the help supplied with the plugin, or have a look online.

Why?

I had some links to display where:

  • the link text had to be the URL (minus the “http://” bit)
  • they had be to rendered as “external” (see below)
  • the URL itself was stored in a custom field

I did the usual checks for existing TXP functionality and/or plugins. Ruud confirmed that stripping a URL of its “http://” required some extra code and was kind enough to suggest some options.

msv_link is a great enhancement to the standard <txp:link/> but I wanted a bit more flexibility.

jra_ext_link provides some interesting functionality, which I’ve “borrowed”.

I’ve bundled up a few ideas into one plugin. To summarise, adi_link provides functionality to:

  • take a URL via an attribute (e.g. http://www.example.com/) and output the link with text “www.example.com”
  • take a URL stored elsewhere (e.g. in a custom field)
  • render link as an “external” link (with specific class & rel)
  • take a URL from the TXP database using a supplied TXP link ID
  • parse & enhance links in an article (like jra_ext_link)
  • render HTML id, HTML rel & CSS class (which can be supplied as tag attributes)
  • render titles & link text (which can be supplied as tag attributes)

Which link?

adi_link will take a URL from a number of sources, depending where it is used & which attributes are specified.

The following can be used to explicitly specify a URL:

  • url attribute
  • id attribute
  • section attribute
  • category attribute
  • container tag mode – adi_link tag encloses the URL

Alternatively, adi_link will take a URL from context:

  • Link form – URL taken from current link
  • Article form – URL taken from link ID in “Article link” custom field (must be manually added)

The following can be used to modify a URL:

  • anchor attribute
  • urlvars attribute

For external use only

By “external link” I mean the XHTML equivalent of HTML target="_blank". When the adi_link attribute ext_link="1" is used the link is rendered, by default, with:

  • class="ext_link"
  • rel="external"

The actual values can be changed but the class gives you a hook to style the link, and the rel is for the javascript that opens the link in a new window. I’ve use a script from Sitepoint in the past or there’s a jQuery version (thanks Gocom):

$(document).ready(function(){
	$('a[rel="external"]').each(function() {
		$(this).attr('target', '_blank');
	});
});

Usage

adi_link can be used as follows:

  • as a single tag: <txp:adi_link/>
  • as a container tag: <txp:adi_link> ... </txp:adi_link>

in:

  • pages
  • forms
  • articles

Examples

Simple link:

<txp:adi_link url="http://www.example.com/" />

- creates link to “http://www.example.com/”, with link text of “www.example.com”

External link:

<txp:adi_link url="www.example.com" ext_link="1"/>

- creates link with HTML attributes: class=“ext_link” & rel=“external”

Container mode – link is enclosed:

<txp:adi_link><txp:variable name="my_url"/></txp:adi_link>

- creates link from URL stored in a TXP variable

Container mode – image is enclosed:

<txp:adi_link url="www.example.com" image="1"><txp:image id="42" /></txp:adi_link>

- creates link to www.example.com, using an image instead of text

Enhance links in an article:

notextile. <txp:adi_link ext_link="1">

* "Link 1":http://www.linkone.com
* "Link 2":http://www.linktwo.com
* "Link 3":http://www.linkthree.com
notextile. </txp:adi_link>

Converts links listed within an article to external links. Note: separate adi_link tags from content with blank lines & use “notextile” to prevent empty <p></p> being generated.

TXP link:

<txp:adi_link id="23" link_text="New text"/>

- outputs a specific TXP link, overriding the stored link text/title

In a link form:

<txp:adi_link class="myclass" />

- when used in a Link Form, will output link with class of “myclass”

Link to page anchor:

<txp:adi_link anchor="top" link_text="back to top" />

- outputs a link to #top on current page

Link to section with additional URL vars:

<txp:adi_link section="mysection" urlvars="var1=value1&var2=value2" link_text="My Section with extras" />

- outputs a link to section “mysection”, with extra URL vars appended

In an article form:

<txp:adi_link image="1"><txp:article_image /></txp:adi_link>

- link URL taken from “Article link” custom field, using image from “Article image” custom field

Version History
  • 0.5
    • new attribute: ‘link_span’
    • fixed lack of recognition for https://
    • fixed up parse problem in container mode
    • cater for URLs in “Article link” custom field
    • now fails more subtly if id not found
    • auto-detects external links
    • new ‘article_id’ attribute
    • TXP 4.6 tag registration
  • 0.4
    • new attribute: ‘short_url_text’
    • new attribute: ‘url_text_only’
    • fix: coding faux pas when setting ext_class (thanks jakob)
  • 0.3
    • new attribute: ‘quiet’
    • new attributes: ‘wraptag’, ‘wraptag_id’, ‘wraptag_class’
    • new attributes: ‘label’, ‘tail’
    • new attribute: ‘title_suffix’
    • new attribute: ‘no_wrap’
    • enhancement: support for “Article link” custom field
  • 0.2
    • fixed: no error message if URL missing
    • new attribute: ‘suppress_href’ (for Phlip)
    • new attribute: ‘anchor’
    • new attribute: ‘section’
    • new attribute: ‘category’
    • new attribute: ‘urlvars’
  • 0.1
    • initial release

Requirements

Nothing special!

Installation

Download and install adi_link in the usual way.

Bugs & deficiencies

  • adi_link won’t notice that links which are supplied in HTML format (e.g. parsed Textile links in articles) may already have a CSS class attribute. It will blindly add a second one if asked to do so.
  • URLs that are supplied without the “http://” prefix when using adi_link in container tag mode won’t be automatically recognised. Use attribute single_url="1" to impose your will.
  • if a link ID is specified in the “Article link” custom field then adi_link can’t be used within the article’s body as well

Let me know if you find any other issues.

Feedback

Comments & suggestions are most welcome.

Credits

Thanks to Ruud for replying to my original forum post.

Thanks to Jean Rajotte for the concept of parsing links in article (jra_ext_link)

Last edited by gomedia (2015-06-17 10:19:30)

Offline

#2 2009-01-13 04:48:44

Phlip
Member
Registered: 2005-03-10
Posts: 36

Re: adi_link – Enhanced links

Awesome plugin, thanks gomedia. I’m using it with a jquery plugin to produce a tooltip. Running into an issue: I’m having trouble removing the actual link. In other words, I don’t need the href attribute. Is there a way to disable that? It looks like the plugin is capable, but everything I’ve tried doesn’t work. Here’s what I got:
<txp:adi_link rel_name=“tip” link_text=“thelink” />
and i still end up with href=“http:///”

Any help? thanks for your time.

Phlip

Offline

#3 2009-01-13 10:55:34

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: adi_link – Enhanced links

Phlip wrote:

Awesome plugin, thanks gomedia.

My pleasure. I use it a lot and I’m glad there’s at least one other person in the world who likes it too!

I’m having trouble removing the actual link … Here’s what I got:
<txp:adi_link rel_name=“tip” link_text=“thelink” />
and i still end up with href=“http:///”

I’ll look into it. Omitting the href attribute is not a scenario I envisaged & the code is obviously trying to make something up. Leave it with me.

Offline

#4 2009-02-01 08:59:32

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: adi_link – Enhanced links

Version 0.2 now available for download.

Summary of changes:
  • fix: no error message if URL missing
  • new attribute: ‘suppress_href’ (for Phlip)
  • new attribute: ‘anchor’
  • new attribute: ‘section’
  • new attribute: ‘category’
  • new attribute: ‘urlvars’

In brief: anchor enables you to insert a page anchor into a URL; section & category provides the capability to output a specific section/category URL; urlvars enables the insertion of GET vars into a link.

See the online help for more details.

Offline

#5 2009-12-08 18:21:14

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

Re: adi_link – Enhanced links

This plugin looks excellent. I’d like to output a specific link via its link_id, and it looks like this plugin can do that, but is it overkill just for that? Is there simpler way to accomplish that?

Offline

#6 2009-12-08 20:19:27

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: adi_link – Enhanced links

nabrown78 wrote:

… but is it overkill just for that? Is there simpler way to accomplish that?

There wasn’t at the time I wrote it & I’m still not sure if there is but the plugin does more than just outputting a link. With every website I build, I keep coming back to it – particularly when associating links with articles.

Offline

#7 2009-12-26 19:24:15

gluteus
Member
From: Switzerland
Registered: 2007-01-20
Posts: 74

Re: adi_link – Enhanced links

Hello Adi

Thanks for your plugin.

Problem: The “external link” doesn’t function.
Here are my specifications:
txp 4.2.0 / FF 3.5.6 / IE 8. Plugin is activated.

I use this link in a article: <txp:adi_link url=“www.monsterweb.ch” ext_link=“1”/>
on this page.

But the links open in the same window/tab. The generated code is:
<a href=“http://www.monsterweb.ch” title=“www.monsterweb.ch” rel=“external” class=“ext_link”>www.monsterweb.ch</a>

Can you please help? I really want to work your plugin.

Thanks
Dave

Offline

#8 2009-12-26 21:34:05

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: adi_link – Enhanced links

gluteus wrote:

Can you please help? I really want to work your plugin.

If you want to open a link in a new window, you need bit of JavaScript to do that. It’s also stated in adi_link’s docs. A link itself can not open in a new window (by XHTML standards).

Example using jQuery library (as you seem to already use it):

$(document).ready(function(){
	$('a[rel="external"]').each(function() {
		$(this).attr('target', '_blank');
	});
});

Offline

#9 2009-12-27 19:19:39

gluteus
Member
From: Switzerland
Registered: 2007-01-20
Posts: 74

Re: adi_link – Enhanced links

Hello Jukka
Thanks a lot, it works great. I should have read the docs more carefully…
dave

Offline

#10 2010-04-21 20:29:16

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: adi_link – Enhanced links

Hello Adi,

This plugin is BRILLIANT!

I once spent a while looking for a great way to use the Links (Content, Links) section of the Admin in Txp to store external links for re-use within a site, so a change to an external resource could be made in one place and reflected thorough the site (the usual benefits of DRY).

This plugin is brilliant for that. And the ability to easily modify a standard text per link is perfect. Thanks! :D Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#11 2010-04-22 07:26:21

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: adi_link – Enhanced links

alanfluff wrote:

Hello Adi, This plugin is BRILLIANT!

Thanks Alan, glad you’ve found it useful.

Cheers,

Adi

Offline

#12 2010-06-21 04:14:09

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: adi_link – Enhanced links

Version 0.3 available for download:

  • new attribute: ‘quiet’
  • new attributes: ‘wraptag’, ‘wraptag_id’, ‘wraptag_class’
  • new attributes: ‘label’, ‘tail’
  • new attribute: ‘title_suffix’
  • new attribute: ‘image’
  • new attribute: ‘no_wrap’
  • enhancement: support for “Article link” custom field

If I’ve broken bits, please let me know.

Offline

Board footer

Powered by FluxBB