Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2023-06-05 11:32:17
- astick360
- Member
- Registered: 2022-05-05
- Posts: 20
Internal links - how to automate
I have two types of links on a page: internal and external. I want them added by option > Content > Links.
The use of categories is possible but not necessary.
I want to insert links using a tag, e.g. <txp:link name=“link nternal 1”/>
Can the txp:link tag only use form: plainlinks, can you point to any one?
Because any: <txp:link form=“links_internal” name=“link nternal 1”/>, doesn’t work.
The second thing is that I would prefer to insert as little as possible and have everything written in forms.
For internal links, I would like to enter only: <txp:link name=“link internal 1”/> and that forms would recognize it best by address, if not by category, whether it’s an internal or external link.
For an internal link, I would like the form to add: rel=“dofollow” and title=“data from the Description field in menu > Content > Links”
How can this be done, whether under the conditions in the form after the address or category, or when entering a link to the article by indicating a different form?
Offline
Re: Internal links - how to automate
I would use some shortcode for this
Create a form name internal link, named e.g. link_internal
, with as contents:
<txp:linklist id='<txp:yield name="id" />'><a class="" href="<txp:link_url />" title="<txp:link_description escape="html" />"><txp:link_name /></a></txp:linklist>
In your article, you then insert the link, where the id
attribute is the ID of your link as found on the links panel :
<txp::link_internal id="xx" />
You can create a similar form for your external links, adding rel="external"
and target="_blank"
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Internal links - how to automate
Further to phiw13’s excellent suggestion, you can also expand the scope to use a single shortcode like this:
<txp:linklist id='<txp:yield name="id" />'>
<a href="<txp:link_url />"<if::yield name="ext"> title="<link::description escape="html" />" rel="dofollow"</if::yield>><link::name /></a>
</txp:linklist>
That means you can specify <txp::link id="59" ext />
to render an external link, or omit the ext
to render an internal link.
But you can go a step further and have the shortcode do that automatically based on URL:
<txp:linklist id='<txp:yield name="id" />'>
<txp:variable name="mylink"><link::url /></txp:variable>
<txp:variable name="is_ext" trim>
<if::variable name="mylink" match="pattern" value="https://example.com/.*">NO<txp:else />YES</if::variable>
</txp:variable>
<a href="<link::url />"<if::variable name="is_ext" value="YES"> title="<link::description escape="html" />" rel="dofollow"</if::variable>><link::name /></a>
</txp:linklist>
If your link begins with https://example.com then it renders it as an internal link, otherwise it’ll add the title
and rel
.
astick360 wrote #335473:
I want to insert links using a tag, e.g. <txp:link name=“link nternal 1”/>
Sadly, the current links implementation is… inconsistent.
- If you use the
<txp:link />
tag then you can specify aname
orid
, but it outputs a hard-coded anchor tag. - If you specify
<txp:linklist>
then you can only use anid
, but you can customise its container contents (e.g. as above in the shortcode) or via theform
attribute. - The
<txp:linkdesctitle />
tag outputs the description astitle
with optionalrel
and hard-codes its output.
It’s a bit of a mess, sorry. Needs an overhaul, ideally.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#4 2023-06-06 07:03:51
- astick360
- Member
- Registered: 2022-05-05
- Posts: 20
Re: Internal links - how to automate
Thanks for the info, both solve the problem and that’s cool. Thanks again.
Offline
Pages: 1