Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-01-24 11:56:07

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

smd_wiki_link: Create Textpattern articles from 404s

If you’ve ever used Wiki software, you’ll know you can create links in articles that don’t yet exist, then view the article and click the (as-yet non-existent) link to be prompted to create the article. This plugin brings that ability to Textpattern.

To use it:

  1. Download the plugin and install/activate it.
  2. Add the code below to your error_default and/or error_404 page template(s).
<txp:if_logged_in>
    <txp:smd_wiki_link />
</txp:if_logged_in>

If you then create an article and put a link like /some-section/an-article-not-yet-created inside it, when you click that link, Textpattern triggers a 404. But, because you’re logged in and have this plugin installed, it will add a Create article link on the 404 page which will redirect you to the Write panel, preselecting some-section, setting the url_title as an-article-not-yet-created and the Title as An Article Not Yet Created for you to write the rest and publish it.

You can customise the link in the <txp:smd_wiki_link /> tag by using either:

  • text="some-text".
  • form="some-form-name".
  • the tag as a container and putting the text between the start and end tags.

There are a few caveats.

  • The plugin tries its best to locate the section based on the permlink scheme in use. For /section/title and /section/id/title it should work fine (well, in the latter case, assuming you can accurately guess which ID is going to be assigned to your article). Your mileage may vary in other schemes because it will locate the first scheme that matches the URL pattern, so if you have multiple sections that use, for example, /year/month/day/title, /id/title or /title then this may not reflect the one you want to put the article in. Just change it when you create the article.
  • Any of the ‘category’ or ‘breadcrumb’ permlink schemes are too complex (slow) to detect so they’re not supported at present. It will skip those and just leave your default section selected.
  • If you use spaces or symbols in your url-title links, the plugin may not match the section accurately. For best results, stick to ASCII characters and hyphen/underscore.

It’s a very niche plugin, but for people who are creating batches of articles with cross-links, or those who want a quick recovery mechanism in case they’ve missed a link somewhere in their site, it can offer a faster workflow for article creation.

The plugin wouldn’t have been as good without the brilliant mind of etc (Oleg) for the ideas on how to auto-detect the permlink scheme. Many thanks for your help.

As always, any problems or improvement suggestions with the plugin, raise an issue.

Hope it’s useful to some folk.


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

#2 2025-01-28 13:52:27

planeth
Plugin Author
From: Nantes, France
Registered: 2009-03-19
Posts: 237
Website GitHub Mastodon

Re: smd_wiki_link: Create Textpattern articles from 404s

This is pure serendipity :D
I was researching wiki, and as usual did a search in this forum to see what’s the opinion of the fine folks here. Et voila !
So if I understand correctly, a wiki is a bunch of pages, which are organised in a free form architecture ?

Offline

Board footer

Powered by FluxBB