Building a Link-Log in Textpattern 4.0
23 March 2006, evening time
While upgrading to the latest version of Textpattern, I decided to clean up the way I implemented my Link-Log. The goal was to minimize the number of hacks needed to get things working. This article should explain what I have done, and should be as terse as possible.
First, download and install the If Section Different plug-in, and install it. Follow the instructions carefully, you will need to change some code in publish.php
.
You will need to make 1 change to publish.php
. You need to add Section
to the select list of the function getNeighbour. The function should now look as follows:
function getNeighbour($Posted, $s, $type)
{
$type = ($type == '>') ? '>' : '<';
$q = array(
"select ID, Title, Section, url_title, unix_timestamp(Posted) as uposted
from ".PFX."textpattern where Posted $type '".doSlash($Posted)."'",
($s!='' && $s!='default') ? "and Section = '".doSlash($s)."'" : filterFrontPage(),
'and Status=4 and Posted < now() order by Posted',
($type=='<') ? 'desc' : 'asc',
'limit 1'
);
$out = getRow(join(' ',$q));
return (is_array($out)) ? $out : '';
}
- Download this code: /static/code/2.txt
I store extra information about links in custom fields. I have a custom field to store the following things: url, referrer, and referrer url.
I use the following form template to actually display the links on the page.
<txp:if_article_list>
<txp:rsx_if_next_section_different>
<div class="post">
<ul class="interesting-link">
<li class="first-child">
<txp:else />
<li>
</txp:rsx_if_next_section_different>
<txp:if_custom_field name="url"><a href="<txp:custom_field name="url" />"><txp:title /></a> <txp:body /><txp:else /><txp:body /></txp:if_custom_field><txp:if_custom_field name="referrer"> (via <a href="<txp:custom_field name="referrer url" />"><txp:custom_field name="referrer" /></a>)</txp:if_custom_field> <txp:comments_invite /><txp:rsx_frontend_edit_link prefix=" [" suffix="]">Edit</txp:rsx_frontend_edit_link></li>
<txp:rsx_if_prev_section_different>
</ul>
</div>
</txp:rsx_if_prev_section_different>
</txp:if_article_list>
<txp:if_individual_article>
<div class="post">
<h2><txp:if_custom_field name="url"><a href="<txp:custom_field name="url" />"><txp:title /> ⇒ </a><txp:else /><txp:permlink><txp:title /></txp:permlink></txp:if_custom_field></h2><p class="inline"> <txp:posted />, <txp:rsx_time_of_day /></p>
<p><txp:body /><txp:if_custom_field name="referrer"> This link was found via <a href="<txp:custom_field name="referrer url" />"><txp:custom_field name="referrer" /></a>.</txp:if_custom_field></p><p><span class="float_left"><txp:comments_invite /></span><span class="float_right"><txp:rsx_frontend_edit_link suffix=" | ">Edit</txp:rsx_frontend_edit_link><txp:permlink>Perma-Link</txp:permlink></span> </p>
</div>
</txp:if_individual_article>
- Download this code: /static/code/3.txt
That should be all there is to it. THere are far more details in the old post on this subject, which are for the most part still valid.
Awesome! Now I can upgrade :) Thanks!
by Josh Dura on March 24 2006, 1:45 pm #