[wp-hackers] Proposed: the_category() - improved separator
flexibilty
Dennis Williamson
dennis at netstrata.com
Mon Oct 11 20:11:01 UTC 2004
I've attached a diff that makes some changes to the_category() in
template-functions-category.php CVS revision 1.39..
It changes the handling of $seperator to improve flexibility to the user.
Calls to the_category() can specify a separator including spaces or not.
Examples:
the_category('/'); produces Blog/Category
the_category(" / "); produces Blog / Category
Before, the spaces were hard-coded in the function and couldn't be overridden.
I also added the ability to override the default separator in calls to
get_category_parents() via an additional parameter, $membersep, in
the_category().
Dennis
Index: template-functions-category.php
===================================================================
RCS file:
/cvsroot/cafelog/wordpress/wp-includes/template-functions-category.php,v
retrieving revision 1.39
diff -u -3 -r1.39 template-functions-category.php
--- template-functions-category.php 10 Aug 2004 05:35:59 -0000 1.39
+++ template-functions-category.php 2 Oct 2004 22:45:13 -0000
@@ -62,7 +62,13 @@
return $link;
}
-function the_category($seperator = '', $parents='') {
+function the_category($seperator = '', $parents='', $membersep='') {
+
+ // dtw - Added $membersep option so the separator between members of a
parent/child link can be specified.
+
+ // dtw - Removed the concatenation of a space after $seperator in order
to improve flexibility. If a space is desired,
+ // dtw - one can be included in the call to this function.
+
$categories = get_the_category();
if (empty($categories)) {
_e('Uncategorized');
@@ -78,14 +84,14 @@
switch(strtolower($parents)) {
case 'multiple':
if ($category->category_parent) {
- $thelist .=
get_category_parents($category->category_parent, TRUE);
+ $thelist .=
get_category_parents($category->category_parent, TRUE, $membersep);
}
$thelist .= '<a href="' . get_category_link(0,
$category->category_id, $category->category_nicename) . '" title="' .
sprintf(__("View all posts in %s"), $category->cat_name) .
'">'.$category->cat_name.'</a></li>';
break;
case 'single':
$thelist .= '<a href="' . get_category_link(0,
$category->category_id, $category->category_nicename) . '" title="' .
sprintf(__("View all posts in %s"), $category->cat_name) . '>';
if ($category->category_parent) {
- $thelist .=
get_category_parents($category->category_parent, FALSE);
+ $thelist .=
get_category_parents($category->category_parent, FALSE, $membersep);
}
$thelist .= $category->cat_name.'</a></li>';
break;
@@ -99,15 +105,18 @@
$i = 0;
foreach ($categories as $category) {
$category->cat_name = $category->cat_name;
- if (0 < $i) $thelist .= $seperator . ' ';
+
+ // dtw - removed the concatenation of a space in the next line, call the
function with $seperator including a space if one is desired
+
+ if (0 < $i) $thelist .= $seperator;
switch(strtolower($parents)) {
case 'multiple':
- if ($category->category_parent) $thelist .=
get_category_parents($category->category_parent, TRUE);
+ if ($category->category_parent) $thelist .=
get_category_parents($category->category_parent, TRUE, $membersep);
$thelist .= '<a href="' . get_category_link(0,
$category->category_id, $category->category_nicename) . '" title="' .
sprintf(__("View all posts in %s"), $category->cat_name) .
'">'.$category->cat_name.'</a>';
break;
case 'single':
$thelist .= '<a href="' . get_category_link(0,
$category->category_id, $category->category_nicename) . '" title="' .
sprintf(__("View all posts in %s"), $category->cat_name) . '">';
- if ($category->category_parent) $thelist .=
get_category_parents($category->category_parent, FALSE);
+ if ($category->category_parent) $thelist .=
get_category_parents($category->category_parent, FALSE, $membersep);
$thelist .= "$category->cat_name</a>";
break;
case '':
More information about the hackers
mailing list