cheap and easy way to show "what links here"
I've recently started making use of alternate search templates. Rather than using them to display alternate search forms, I'm using them to dynamically generate lists of blog entries that contain a certain text.
One of the things I've done is to create a "what links here" page linked to from each entry's individual archive page that lists all entries in the blog that link to that entry.
I created the alternate search template (see Link Search Template here). The design resembles other listing pages on my blog rather than looking like a search result page or search form.
In my individual entry archive template, I use the following code to link to the alternate search template and pass the search string:
<p>
<a href="<$MTCGIPath$><$MTSearchScript$>?Template=links&search=<$MTEntryPermalink$>
&IncludeBlogs=<$MTBlogID$>&entry=<$MTEntryTitle encode_url="1"$>">What links here</a>: View a list of other entries in this blog (if any) that link to this entry
</p>
(note: the search URL should all be on one line but I've added line breaks to display it properly here)
This calls the appropriate alternate search template (Template=links) and passes the URL as the search string (search=<$MTEntryPermalink$> ) so that all entries that contain this URL (i.e., that link to the URL) are returned as search results.
I've added entry=<$MTEntryTitle encode_url="1"$> as part of the URL. What's this? It's a little trick using the MTCgi plugin. MTCgi allows you to pass information in the URL and then pull it out on the CGI page (in this case, the CGI is the search script).
On the Link Search Template, I then have the following:
This page shows a list of all entries at <$MTBlogName$> that link to <a href="<$MTSearchString$>"><MTCgiParams include="entry"><$MTCgiParamValue decode_url="1"$></MTCgiParams></a>
Here, the MTCgi template tags pull in the "entry" parameter that I set, and display it. The decode_url="1" part is courtesy of the DecodeURL plugin since although MT has encode_url as an attribute, it doesn't have decode_url for some reason.
The reason for all of this is that I wanted the "What links here" result page to display the name of the entry that has the URL, but since the URL is just a string of text, the search script doesn't know what the name of the entry is. So I'm passing along the title of the entry in the search call from a page that does know about it (the individual archive page for the entry) to the search script so that the search template can display it.
You can see it in action here, which you can access from here by following the "what links here" link in the Further Reading | Related Entries area.
I had been considering various ways to show what entries are linking to a given entry. I could have hacked the trackback script to allow self-trackbacks and then gone through to find all the entries that are linking to other entries and save them again to send the ping.
Doing it with an alternate search template (and a little help from MTCgi and DecodeURL) is much easier, although you do have to follow a link to view the list.
Subscribe to this blog's feed