Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-08-26 12:56:22

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,674
GitHub Twitter

A little tip for the category_list tag (TXP 4.0.4)

Cause I’ve need some separators and linktitle in this (amazing) category_list tag, I change the original code in taghandlers.php like this :

// output href list of site categories

	function category_list($atts)
	{
		global $s, $c;

		extract(lAtts(array(
			'active_class' => '',
			'break'        => br,
			'categories'   => '',
			'class'        => __FUNCTION__,
			'exclude'      => '',
			'label'        => '',
			'labeltag'     => '',
			'parent'       => '',
			'section'      => '',
			'this_section' => 0,
			'type'         => 'article',
			'wraptag'      => '',
			'separator'    => '',
			'linktitle'        => '',
		), $atts));

		if ($categories)
		{
			$categories = do_list($categories);
			$categories = join("','", doSlash($categories));

			$rs = safe_rows_start('name, title', 'txp_category', 
				"type = '$type' and name in ('$categories') order by field(name, '$categories')");
		}

		else
		{
			if ($exclude)
			{
				$exclude = do_list($exclude);

				$exclude = join("','", doSlash($exclude));

				$exclude = "and name not in('$exclude')";
			}

			if ($parent)
			{
				$qs = safe_row('lft, rgt', 'txp_category', "name = '$parent'");

				if ($qs)
				{
					extract($qs);

					$rs = safe_rows_start('name, title', 'txp_category', 
						"(lft between $lft and $rgt) and type = '$type' and name != 'default' $exclude order by lft asc");
				}
			}

			else
			{
				$rs = safe_rows_start('name, title', 'txp_category', 
					"type = '$type' and name not in('default','root') $exclude order by name");
			}
		}

		if ($rs)
		{
			$out = array();

			while ($a = nextRow($rs))
			{
				extract($a);

				if ($name)
				{
					$section = ($this_section) ? ( $s == 'default' ? '' : $s ) : $section;

					$out[] = tag(str_replace('& ', '& ', $title), 'a', 
						( ($active_class and ($c == $name)) ? ' class="'.$active_class.'"' : '' ).
						' href="'.pagelinkurl(array('s' => $section, 'c' => $name)).'"title="'.$linktitle.$title.'"'
					).$separator;
				}
			}

			if ($out)
			{
				return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class);
			}			
		}

		return '';
	}


I’m not PHP developer, so could you tell me if it’s perfect. This change above woks well.
Perhaps this a good idea to change the category_list tag in the core? What do you think?

Cheers,
PAtrick.

(Edit: updated to display code properly. -Mary)

Last edited by Mary (2006-08-27 02:58:15)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#2 2006-08-27 03:02:57

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: A little tip for the category_list tag (TXP 4.0.4)

  • With the separator, that is the purpose of the “break” attribute.
  • I’m a little confused regarding your $linktitle addition, would that not apply the exact same link title to every category link?

Offline

Board footer

Powered by FluxBB