Go to content Go to sidebar

Browsing the "Colophon" category...

Textpattern custom_url_func upgrade

My upgrade to Textpattern 4.2.0 was almost trouble free. The only problem was that the built-in newer, older, category1 and category2 functions weren't working.

After crawling through the source, I realized that the custom_url_func function signature had been redefined to include an optional argument. This change allowed the custom_url_func to be invoked by the newer, older, category1 and category2 functions (amongst others). Once I understood the problem, it was easy to add the required functionality.

function idx_permlinkurl($article_array, $link_type=0)
{
    global $prefs;

if (empty($article_array)) return; extract($article_array);

if ( $link_type == PAGELINKURL ) { // PAGE LINK mode $page = $article_array['pg']; if ( empty($page) || $page == 0 || $page == 1 ) { $page_suffix = ''; } else { $page_suffix = '?pg='.$page; }

$category = $article_array['c']; if ( !empty($category) ) { if (empty($page_suffix)) { $page_suffix = '?c='.$category; } else { $page_suffix = $page_suffix . '&c=' . $category; } }

$section = $article_array['s']; if ($section == 'default') { return hu.$page_suffix; } else { return hu.$section.$page_suffix; } } else { // ARTICLE LINK mode if (!isset($title)) $title = $Title; if (empty($url_title)) $url_title = stripSpace($title); if (empty($thisid)) $thisid = $ID;

if ($prefs['attach_titles_to_permalinks']) { return hu."id/$thisid/$url_title"; } else { return hu."id/$thisid/"; } } }

$prefs['custom_url_func'] = 'idx_permlinkurl';

Surrounding Articles Tridux

It was probably a case of premature optimization on my part, but my idx_article Textpattern plugin assumed that a larger article id would always be more recent than a smaller article id.

That was appropriate for most of my posts. However, my focus pages are periodically updated and the resulting sequence got a bit peculiar. I’ve updated the plugin so that the surrounding_articles tag always displays posts in chronological order.


I Need a Life

aka “I’ve got categories.”

Textpattern has both sections and categories. The difference is a bit subtle; but the upshot was that Take the First Step was only using sections for Technology and Sports out of the chute.

That’s changed. Categories are up and I tweaked the templates to include a category list. Since that is presentation rather than content, any curious subscribers should make a real visit to check it out.

And then I burnt the better part of two hours adding categories to old posts in the Sports section. I really need to get a life.


Textpattern and custom_url_func

One of my biggest concerns in moving from Radio Userland to Textpattern was preserving inbound links. My initial approach used mod_rewrite and year-month-day mode. This was fairly effective.

But I wasn't completely satisfied. Year-month-day mode is based upon GMT, moving posts after 7pm moved into the next day. And it never really felt like a good long-term solution.

I didn't want to wait for the ideal solution, so I added an id based RewriteRule, created index pages using the newly defined id based links, and started a project to update all my internal links. This allowed me move all my content from Radio Userland to Textpattern.

Now, my only problem was that Take the First Step was using two url modes: year-month-day for Textpattern generated links and my id mode for manually generated links in my content.

The final piece of my solution was “custom_url_func”. I added a plugin that codified my id mode as a “custom_url_func”, and unified all my internal links into a single mode. The entire solution looks like this:

  1. mod_rewrite and year-month-day mode to preserve old inbound links.
  2. more mod_rewrite to handle an alternate link mode of id/NNNN/url-title. The new rules simply extract the post id from the link and pass it on as part of the query string.
    
     RewriteRule ^id/([0-9]+)/?$ index.php?id=$1 [L]
     RewriteRule ^id/([0-9]+)/[^/]+$ index.php?id=$1 [L]
    
  3. A custom_url_func plugin to specify an alternate link format for all Textpattern generated article links. The business end of the plugin follows:
    
    function idx_permlinkurl($article_array)
    {
    	global $prefs;

    if (empty($article_array)) return; extract($article_array);

    if (!isset($title)) $title = $Title; if (empty($url_title)) $url_title = stripSpace($title); if (empty($thisid)) $thisid = $ID;

    if ($prefs['attach_titles_to_permalinks']) { return hu."id/$thisid/$url_title"; } else { return hu."id/$thisid/"; } }

    $prefs['custom_url_func'] = 'idx_permlinkurl';

29 Dec 2009: A custom_url_func upgrade for Textpattern 4.2.0


Index Pages in Textpattern

Java Tutorials are the big draw here at Take the First Step. The easy way to build my new tutorial landing pages would have been via a Textpattern category. But I wanted too much control over both the content and the presentation to go that route. My method was to:

  1. Create a section dedicated to focus pages. I elected to keep my focus posts off the front page and out of my syndication feeds – YMMV.
  2. Hand roll each summary page as a focus section post. This allowed me to simply copy my existing focus pages (implemented as tables, text paragraphs, and definition lists) into Textpattern.
  3. Control presentation with a focus template page. My focus template is very similar to my main template – I simply tweaked my Surrounding Articles plugin so that I could optionally limit the article list to a specific section.
  4. Clean urls with some htaccess magic. Because I have a small number of focus pages, I map focus/java, focus/cms, and focus/weblog to index.php?id=NNNN (where NNNN is the appropriate id number for each focus page).

It was a bit more work, but I’m pretty happy with the result. It doesn’t really scale, but I only expect small numbers (only three at present).


Feed Updates

I really need to pay more attention to my log files. I have been monitoring for 404 “file not found” response codes to detect any fallout from my .htaccess frenzy from a few weeks ago.

But I haven’t been looking for anything else. Until tonight – when I realized that I haven’t checked my feed subscription levels in quite a while. And I was even more surprised when I realized that I had neglected to redirect all of my old Radio Userland feeds to their new Textpattern equivalents.

So I added some more htaccess redirects, I claimed some more feeds in Bloglines and I think that all my old feeds are back in business.


Site Renovation

There is a certain appeal to a simple white web page with text. But it was time to liven the joint up. Not finding a suitable image of my own, I started searching at iStockphoto.

A bit of rotating and cropping and Take the First Step has a new header graphic.


« Previous