[wp-hackers] Need advice on category link parsing

David Coppit david at coppit.org
Tue Jan 17 15:44:03 GMT 2006


Hey all,

I'm trying to make my category order plugin more robust. Right now I hook
list_cats like this:

 	function sort_categories($original_html) {
 		if(strstr($original_html, "<li>")) {
 			$islist = TRUE;
 		} elseif(strstr($original_html,'<br />')) {
 			$islist = FALSE;
 		} else {
 			// Probably an item instead of the whole list
 			return $original_html;
 		}

 		$slug_to_item = category_order::parse_html($original_html,$islist);

 		$new_html = category_order::build_list_html($slug_to_item,$islist);

 		return $new_html;
 	}

AFAICT there is no hook for modifying the category list data structure
prior to WordPress generating the HTML. As a result, I have to dissect the
WordPress HTML, sort the categories, then rebuild the HTML. Ug!

Parsing the HTML is a hassle since the user can specify goofy permalink
structures, so that the category list items look like:

   <li> <a href="http://blog/category/slug/">Cat1</a>

or maybe

   <li> <a href="http://blog/?cat=1">Cat1</a>

Is there an easier way? Or should I get the permalink_structure and try to
do matching on the HTML? If I have to parse the HTML, is there an easy way
to get the category ID from the slug? (Are slugs-to-cat_ids a one-to-one
mapping?)

Thanks,
David

_____________________________________________________________________
David Coppit                           david at coppit.org
The College of William and Mary        http://coppit.org/

"If we knew what it was we were doing, it would not be called research,
would it?" -- Albert Einstein


More information about the wp-hackers mailing list