Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-09-05 16:16:22

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Display a specific link in an articles body

Is it possible to do the following within an article body? I’m having something of a brain freeze regarding this.

<txp:link id="1" />

Offline

#2 2011-09-05 16:43:57

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: Display a specific link in an articles body

Hi Ross. I don’t think that it is possible but I can think of many applications where a comma separated list of link ids could become very useful.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2011-09-05 17:23:57

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Re: Display a specific link in an articles body

That’s a pity. I was hoping the Links tag would have something built in as I’ve managed to accomplish the same thing with Files by using this:

<txp:file_download id="1" />

In the new website I’m working on there will be a number of individual links within different articles that point to external websites. I was hoping to use Textpatterns Links to keep them organised. That way I could check all the links there and any changes would be automatically pushed out to these articles. The thought of having to go through each article with a link and manually change it doesn’t appeal to me.

—Edit—
I wonder if this might do the trick. I’ll have to investigate further.

http://textpattern.org/plugins/791/wet_linkinfo-extract-a-managed-links-properties

Last edited by Algaris (2011-09-05 17:38:46)

Offline

#4 2011-09-05 18:07:43

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: Display a specific link in an articles body

Algaris wrote:

That way I could check all the links there and any changes would be automatically pushed out to these articles.

It’s exactly what was thinking of. If it happens we will have uniformity to the whole txp system. files/images/links all having very similar tags.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2011-09-05 18:32:11

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Re: Display a specific link in an articles body

Someone should make a feature request ;-)

Offline

#6 2011-09-05 18:57:19

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display a specific link in an articles body

r3586 :)

Last edited by els (2011-09-05 18:57:43)

Offline

#7 2011-09-05 18:57:32

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Display a specific link in an articles body

This r3586 is an addition to txp:linklist rather than txp:link itself, but in view of the fact that txp:linklist will now return any number of links by id and display a linklist form for that link or links – it should cover this base.

Ok :) 13 seconds!

Last edited by rsilletti (2011-09-05 18:59:25)

Offline

#8 2011-09-05 21:58:23

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

Re: Display a specific link in an articles body

Algaris wrote:

Someone should make a feature request ;-)

Or you could use a plugin … adi_link … which would let you do: <txp:adi_link id="1" />

Offline

#9 2011-09-06 00:17:51

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display a specific link in an articles body

The OP’s request reminded me of this technique.

<txp:linklist limit="1" sort="FIELD(ID,1) desc">
  <txp:link />
</txp:linklist>

Not tested (I have no links, in none of my installations.)
Edit: I’ve created some links in the meantime and found the tag needs the desc sort order parameter in order to work (added in the above code). So here’s a tag combo to pick out one specific link by ID.

Last edited by uli (2011-09-08 15:10:55)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2011-09-06 08:02:18

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Re: Display a specific link in an articles body

rsilletti wrote:

This r3586 is an addition to txp:linklist rather than txp:link itself, but in view of the fact that txp:linklist will now return any number of links by id and display a linklist form for that link or links – it should cover this base.

That will be a huge help. Can’t wait for the next Textpattern release =D

gomedia wrote:

Or you could use a plugin … adi_link … which would let you do: <txp:adi_link id="1" />

Thanks Adi this does just what I wanted and it’s so easy to use.

uli wrote:

The OP’s request reminded me of this technique.

<txp:linklist limit="1" sort="FIELD(ID,1)">
  <txp:link />
</txp:linklist>

Not tested (I have no links, in none of my installations.)

Uli I tried your suggestion but for some reason it would only output the link with ID 1 no matter what I change it to. I’m not too worried about that now though.

Last edited by Algaris (2011-09-06 08:07:12)

Offline

#11 2011-09-08 15:03:35

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display a specific link in an articles body

Algaris wrote:

Uli I tried your suggestion but for some reason it would only output the link with ID 1 no matter what I change it to. I’m not too worried about that now though.

Wouldn’t be, either ;)

Tried it now in order to see what didn’t work: it needs a desc. No clue why it fails with asc (and without a value = asc, respectively).


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#12 2011-09-08 17:55:32

testdeputy
Member
Registered: 2011-05-29
Posts: 29

Re: Display a specific link in an articles body

Came up with this:
1) use a custom field named links and fill it with the id (one or more) for the link(s) you want to show, comma-separated.
2) then in your article form:

<txp:if_custom_field name="links">
<txp:php>
$links=explode(",",$GLOBALS["thisarticle"]["links"]);
$sort=array();
$number=1;
$links=array_reverse($links);
foreach($links as $link) {
	$sort[]="WHEN $link THEN $number";
	$number++;
};
global $variable;
$variable["limit"]=count($links);
$variable["sort"]="CASE id ".join(" ",$sort)." END DESC";
</txp:php>
<txp:linklist limit='<txp:variable name="limit" />' sort='<txp:variable name="sort" />' wraptag="ul" break="li">
	<txp:link_id /> = <txp:link />
</txp:linklist>
</txp:if_custom_field>

Last edited by testdeputy (2011-09-08 17:58:55)

Offline

Board footer

Powered by FluxBB