Go to content Go to sidebar

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';