I added the Nicer Archives code snippet from WP Wiki. I tried to use the “upgraded” versions of it (from Weblog Tools Collection) but they borked — big time.
When you enter the page, it shows the posts of the current year. Then you can sort the posts by date, title, or category; ascending or descending; and from all years or one year at a time (there is only one year, for now). The original script had a possibility sort by author but because there’s only me, I commented it out.
Time format is date.month.year.
On to the archives »
The calendar showed as January 2004 so I started to look for a way to remove it. Easier said than done. Well, not really, but I didn’t think of echoing the variable in my if-test to see what it’s out put was. This is what I wrote (first):
<?php $thispage = $_SERVER[‘HTTP_HOST’].$PHP_SELF;
if ($thispage != “www.mypage.xxx/blog-folder/pagename.php“) { ?>
<!-- CALENDAR -->
<li id=”calendar”>
<?php get_calendar(); ?>
</li>
<?php } ?>
http_host + php_self return the url of a php page a without the http (as that’d be the protocol)
Then I tried what $_SERVER[‘REQUEST_URI’] does and it echoed the path without the host. Nifty. Thus, I changed the code to
<?php $thispage = $_SERVER[‘REQUEST_URI’];
if ($thispage != “/blog-folder/pagename.php“) { ?>
<!-- CALENDAR -->
<li id=”calendar”>
<?php get_calendar(); ?>
</li>
<?php } ?>
[edit: Nov 22/Dec 15, ’04/Jan 5, ’05] I had an oddly titled post which messed up the archive. Well, not exactly *mess* but because it had an less-than sign at the beginning it was archived under L, but first alphabetically. After some testing, I figured out how to prevent this. From the WP Wiki I found a function sanitize_title_with_dashes
which I used in the archive code, this is in the function archive_header: This worked when my odd titles included only one starting with A. But when there was one with D, I noticed the code didn’t work. Why? Because it compares the first letter if the current title to the previous one and the query sorts the odd titles at first. Well, I took another approach to this. All odd titles will be categorized under # (I know it means ‘number’ but here it’s just some non-alphabetic character). A new try, a * I had in one of the titles wouldn’t be recognized, probably because the line starting with preg_match matches only letters and numbers, so I changed that to match any one character (at the beginning). Hopefully this will prove working with my strange titles…
elseif ('title' == $orderby) {
preg_match('/.{1}/i', $post->post_title, $match);
$thisletter = ucfirst($match[0]);
if (!ctype_alpha($thisletter)) { $thisletter = '#'; }
if ($thisletter != $previous) {
$output .= "<br/>".$thisletter;
}
$previous = $thisletter;
The highlighted part checks if the first letter of the title is NOT an alphabetic character, if it’s true that it’s NOT one, the letter will be a ‘#’. Now all the odd titles will be grouped at the beginning of the list of titles (or end if the order’s descending) . [/edit]