Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Clean urls with cbs_category_list? - help!
TXP’s normal <txp:category_list />
produces link with urls like www.site.com/category/category_name. But I wanted a category list that includes the number of articles in each category, so I am using cbs_category_list
. Works great, except it outputs messy urls. Does anyone know how I could modify the plugin (see code below) to make it output clean urls? It’s such a short plugin I thought I could figure it out, but my PHP skills are…lacking.
/*
cbs_category_list v0.9
by Christophe Beyls [http://www.digitalia.be]
*/
function cbs_category_list($atts)
{
global $s, $c;
extract(lAtts(array(
'label' => '',
'labeltag' => '',
'break' => 'br',
'wraptag' => '',
'parent' => '',
'posted' => '',
'section' => $s,
'sticky' => '',
'showcount'=> '',
'class' => __FUNCTION__,
'activeclass'=> ''
),$atts));
$parent = ($parent) ? " AND c.parent = '$parent'" : '';
$showcount = ($showcount == 'true') ? ', COUNT(*) AS count' : '';
$sticky = ($sticky == 'true') ? '5' : '4';
switch($posted) {
case 'all':
$posted = '';
break;
case 'future':
$posted = ' AND t.Posted >= now()';
break;
default:
$posted = ' AND t.Posted < now()';
}
if($section == 'default') {
$table = ', `'.PFX.'txp_section` AS s';
$sqlsection = 's.name AND s.on_frontpage = 1';
} else {
$table = '';
$sqlsection = "'$section'";
}
$rs = startRows(
'SELECT c.name, c.title'.$showcount.' FROM `'.PFX.'txp_category` AS c, `'.PFX.'textpattern` AS t'.$table
.' WHERE (c.name = t.Category1 OR c.name = t.Category2) AND c.type = \'article\' AND t.Section = '.$sqlsection.$parent.$posted
.' AND t.Status = '.$sticky.' GROUP BY c.name ORDER BY c.title'
);
if(!$rs)
return '';
$count = '';
$out = array();
while($a = nextRow($rs)) {
extract($a);
$out[] = tag(str_replace('& ','& ', $title), 'a', ' href="'.pagelinkurl(array('c'=>$name, 's'=>$section))
.(($activeclass && ($s == $section) && ($c == $name)) ? '" class="'.$activeclass.'"' : '"')).($count ? ' ('.$count.')' : '');
}
return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class);
}
Offline
Re: Clean urls with cbs_category_list? - help!
It uses pagelinkurl()
to generate URLs, same as category_list
. URLs such as /section/?c=category
are as clean as Txp currently produces for section-based category lists.
Code is topiary
Offline
Re: Clean urls with cbs_category_list? - help!
Oh okay I get it. So if you are cool with ignoring the section, then txp can produce a url like www.site.com/category/category_name
, but if you want it sort of section-sensitive, you’re stuck with messy urls. Okay, no biggie. If I recall correctly, I think gbp_permanent_links
can help.
Offline