[wp-hackers] Proposed: wp_title() - display day with date and
improved separator flexibility
Dennis Williamson
dennis at netstrata.com
Mon Oct 11 20:11:05 UTC 2004
I've attached a diff that makes some changes to wp_title() in
template-functions-general.php CVS revision 1.51
It changes wp_title so the day is displayed (in addition to the year and
month) when you have .../index.php?m=yyyymmdd.
It also changes the handling of $sep to improve the flexibility to the
user. The default call, wp_title(), still functions as before with respect
to the default separator, but if the user specifies a separator, spaces can
be included or not.
Examples:
wp_title('/'); produces Blog/Category
wp_title(" / "); produces Blog / Category
Same idea for a date or a post title.
Before, the spaces were hard-coded in the function and couldn't be overridden.
Dennis
Index: template-functions-general.php
===================================================================
RCS file:
/cvsroot/cafelog/wordpress/wp-includes/template-functions-general.php,v
retrieving revision 1.51
diff -u -3 -r1.51 template-functions-general.php
--- template-functions-general.php 30 Sep 2004 17:56:16 -0000 1.51
+++ template-functions-general.php 2 Oct 2004 22:05:57 -0000
@@ -121,7 +121,15 @@
return $output;
}
-function wp_title($sep = '»', $display = true) {
+function wp_title($sep = ' » ', $display = true) {
+
+ // dtw - changed $sep to include spaces in the default and removed spaces
from $title
+ // dtw - which preserves previous behavior and improves flexibility since
the user
+ // dtw - can choose whether to include spaces in the function call
instead of them
+ // dtw - being hard-coded
+
+ // dtw - changed processing of $m so the day is also displayed when
?m=yyyymmdd
+
global $wpdb;
global $m, $year, $monthnum, $day, $category_name, $month, $posts;
@@ -150,18 +158,32 @@
// If there's a month
if(!empty($m)) {
- $my_year = substr($m, 0, 4);
- $my_month = $month[substr($m, 4, 2)];
- $title = "$my_year $sep $my_month";
+ $title = substr($m, 0, 4); // year
+
+ // dtw - added length tests (which prevent trailing $sep)
+
+ if (6 <= strlen($m)) {
+ $title .= $sep . $month[substr($m, 4, 2)]; // month
+ }
+
+ // dtw - added "day"
+
+ if (8 <= strlen($m)) {
+ $day = substr($m, 6, 2);
+ if ('0' == substr($day, 0, 1)) {
+ $day = substr($day, 1); // strip leading zero
+ }
+ $title .= $sep . $day;
+ }
}
if (!empty($year)) {
$title = $year;
if (!empty($monthnum)) {
- $title .= " $sep ".$month[zeroise($monthnum, 2)];
+ $title .= $sep . $month[zeroise($monthnum, 2)];
}
if (!empty($day)) {
- $title .= " $sep ".zeroise($day, 2);
+ $title .= $sep . zeroise($day, 2);
}
}
@@ -173,9 +195,9 @@
// Send it out
if ($display && isset($title)) {
- echo " $sep $title";
+ echo $sep . $title;
} elseif (!$display && isset($title)) {
- return " $sep $title";
+ return $sep . $title;
}
}
More information about the hackers
mailing list