Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-11-24 02:48:39

jagorny
Member
From: Portland, OR
Registered: 2006-08-24
Posts: 39
Website

Deep linking plugin?

So I have been working with one of my sites and I have been scouring txp.org trying to find a plugin that I thought did this already.

I’d like to be able to create deep links for keyword content. In my example, during the course of writing tutorials sometimes I need to use technical language. For some of these terms it is possible to just do a tooltip – but for others I’d like to be able to either link every instance of a piece of text to a link, or else just the first instance.

It would also be nice to be able to gather a list of the terms replaced in the article and be able to list them.

I’ve found search and replace tags that use inline parms. I’ve found an7’s plugin that is really close – in that it uses a coded array. Somehow I thought I had seen a plugin that did exactly this for TXP in the past, e.g. it built a table with two columns and you could just add rows to it on the admin side.

Maybe I’m dreaming. Or not sleeping enough.

I suppose I could give a crack at writing it if it doesn’t exist yet.

I know that Wordpress has at least one SEO plugin that does this. It could be that I’m thinking of that?

Oh well… if this doesn’t get any pings I will see if I can cobble it with parts from old robots.

Offline

#2 2013-11-24 09:40:11

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Deep linking plugin?

jagorny wrote:

I’ve found search and replace tags that use inline parms. I’ve found an7’s plugin that is really close – in that it uses a coded array.

Straightforward replacements can easily mess your site, replacing text everywhere, including tags attributes and scripts. A relatively robust way is to define a JSON-encoded array of replacement pairs (that you could store in some persistent variable with adi_variables), and use this instead of <txp:body />:

<txp:variable name="replacements">{"replace" : "<a href=\"#\">replace</a>", "important" : "<strong>important</strong>"}</txp:variable>

<txp:etc_query data='<txp:body />' 
	replace="//*[name() != 'script']/text()&={$json_decode({?replacements}|1).strtr({string(.)}|$)}"
	functions="strtr, json_decode" />

This will replace every occurrence of “replace” with replace and so on. You can also target only some parts of the article body.

Edit: see it in action here.

Last edited by etc (2013-11-24 18:23:40)

Offline

Board footer

Powered by FluxBB