Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Today 03:19:46

Melonking
Member
Registered: 2022-05-10
Posts: 23
Website

Redirect to external articles

Hi hi,
I feel like the answer may be quite simple but I’ve not found a way to do it easily off the bat!

I use my TXP site as a blog, however not all of my writing is hosted on my blog! I would still like my blog to act as a directory for all my writing though so that people can follow it as a single RSS feed and I can offer it as a single link.

I would to have some articles that appear just like regular articles in the list with keywords, publish dates, excerpts etc ~ however when you click on them they redirect to an external link in a new tab instead of an actual article. It would also be handy if there was some icon next to them to identify them as external articles.

e.g. imagine this is my blog section sorted by most recent:
  • Article A – internal article
  • Article B – external article
  • Article C – internal article
  • Article D – internal article
  • ect

I suppose I could include some sort of HTML redirect, or JavaScript based redirect in the body of the article; but that seems hacky; I’m wondering if there’s a better way to do it?

Last edited by Melonking (Today 03:20:20)


The world will tremble

Offline

#2 Today 07:14:43

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

Re: Redirect to external articles

You could use a custom field and a php redirect in the head.

ie. you could have a custom field named external which could house the external urls.

In the head of the page add

<txp:if_custom_field name="external" />
<txp:php>header("Refresh:0; url=<txp:custom_field name='external' />"); </txp:php>
</txp:if_custom_field >

regarding a new tab. Maybe somebody could shed some light.


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 Today 07:23:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,560
Website GitHub

Re: Redirect to external articles

I would do that using a custom field. I do exactly this on a site of mine.

Create a field called (for example) “external_link” and put the destination URL in the articles you want to direct elsewhere. Then in your template code that displays article lists:

<txp:if_custom_field name="external_link">
<a href="<txp:custom_field name="external_link" />"><txp:title /></a>
<txp:else />
<txp:permlink><txp:title /></txp:permlink>
</txp:if_custom_field>

Job done, I think. If you add a class to your titles, you can also hook into them with CSS to display the external link indicator.


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 Today 07:40:32

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,284
Website

Re: Redirect to external articles

Same idea as Stef above – and add target="_blank" to your links:

<a href="<txp:custom_field name="external_link" />" target="_blank"><txp:title /></a>

Yiannis‘ idea would work too, but you can’t force the destination page to open in a new tab, afaik.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#5 Today 07:41:17

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

Re: Redirect to external articles

Further to what Bloke suggested, I would include the external link attribute in the url.

<txp:if_custom_field name="external_link">
<a rel="external" href="<txp:custom_field name="external_link" />"><txp:title /></a>
<txp:else />
<txp:permlink><txp:title /></txp:permlink>
</txp:if_custom_field>

Also, If you do not have control over the external sites, I would have

<a rel="external noopener" href="<txp:custom_field name="external_link" />"><txp:title /></a>

… and here’s the css I’m using on our site

a[rel~=external]:after {
content:"\00a0\21D7";
display:inline-block;
position:relative;
padding:0
}

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

Offline

#6 Today 07:42:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,560
Website GitHub

Re: Redirect to external articles

Ooh, good catch on the rel. No need for the class then. Neat.


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

Board footer

Powered by FluxBB