Wordpress Install
I decided to use Wordpress for this blog as it seems to be the current ’standard’. It was nice to se that it works nicely out of the box after the short install. However, being as awkward as I am, I decided that that I wanted to tweak it a bit:
Firstly I didn’t want to have a dynamic url system, so opted to use WP’s ‘permalinks’ setup. But again I didn’t want to use their standard folder architecture that 1,000s of others also use e.g. blog.com/archive/2005/11/post-title.html. So I decided to use the following structure:
- www.nott.org
- /home-page.html
- /content-page-title.html
- /blog/
- /blog/post-title.html
- /blog/category/
- /blog/2005/11/ (archive dates)
- /blog/feed/feed-format.xml
- /blog/feed/category/feed-format.xml (category feed)
- /blog/feed/post-title.xml (comments feed)
To do this took a few mod_rewrite lines in Apache:
RewriteEngine On
RewriteRule ^/blog/$ / [R=301]
RewriteCond %{REQUEST_URI} !^/index\.html$
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^/([A-Za-z0-9-_]+).html$ /index.php?pagename=$1 [QSA]
RewriteRule ^/blog/([A-Za-z0-9-_]+).html$ /index.php?name=$1 [QSA]
RewriteRule ^/blog/([0-9]+)/([0-9]+)/$ /index.php?m=$1$2 [QSA]
RewriteRule ^/blog/feed/(rdf|rss|rss2|atom).xml$ /wp-feed.php?feed=$1 [QSA]
RewriteRule ^/blog/feed/comments/([A-Za-z0-9-_]+).xml$ /wp-feed.php?feed=rss2&name=$1 [QSA]
RewriteRule ^/blog/([A-Za-z0-9-_]+)/$ /index.php?category_name=$1 [QSA]
RewriteRule ^/blog/feed/([A-Za-z0-9-_]+)/(rdf|rss|rss2|atom).xml$ /wp-feed.php?category_name=$1&feed=$2 [QSA]
Then some small changes to some of the wordpress php functions (i know this will make upgrades tricky, but if I know what changes I’ve made, it should be possible):
/wp-includes/feed-functions.php
global $id;
if (” != get_settings(‘permalink_structure’))
$url = str_replace(“.html”,“.xml”,str_replace(“/blog/”, “/blog/feed/comments/”, get_permalink()));
else
$url = get_settings(‘home’) . “/$commentsrssfilename?feed=rss2&p=$id”;
return apply_filters(‘post_comments_feed_link’, $url);
}
/wp-includes/template-functions-links.php
global $wp_rewrite;
$do_perma = 0;
$feed_url = get_settings(’siteurl’);
$comment_feed_url = $feed_url;
$permalink = $wp_rewrite->get_feed_permastruct();
if (” != $permalink) {
if ( false !== strpos($feed, ‘comments_’) ) {
$feed = str_replace(‘comments_’, ”, $feed);
$permalink = $wp_rewrite->get_comment_feed_permastruct();
}
$permalink = str_replace(‘%feed%’, $feed, $permalink);
$permalink = preg_replace(‘#/+#’, ‘/’, “/$permalink/”);
$output = get_settings(‘home’) . “/blog/feed/” . $feed . “.xml”;
} else {
if ( false !== strpos($feed, ‘comments_’) )
$feed = str_replace(‘comments_’, ‘comments-’, $feed);
$output = get_settings(‘home’) . “/?feed={$feed}”;
}
return apply_filters(‘feed_link’, $output, $feed);
}
template-functions-post.php
parse_str($args, $r);
if ( !isset($r[‘depth’]) ) $r[‘depth’] = 0;
if ( !isset($r[’show_date’]) ) $r[’show_date’] = ”;
if ( !isset($r[‘child_of’]) ) $r[‘child_of’] = 0;
if ( !isset($r[‘title_li’]) ) $r[‘title_li’] = __(‘Pages’);
if ( !isset($r[‘echo’]) ) $r[‘echo’] = 1;
$output = ”;
// Query pages.
$pages = & get_pages($args);
if ( $pages ) :
if ( $r[‘title_li’] )
$output .= ‘<li class="pagenav">’ . $r[‘title_li’] . ‘<ul>’;
// Now loop over all pages that were selected
$page_tree = Array();
foreach($pages as $page) {
// set the title for the current page
$page_tree[$page->ID][‘title’] = $page->post_title;
$page_tree[$page->ID][‘name’] = $page->post_name;
// set the selected date for the current page
// depending on the query arguments this is either
// the createtion date or the modification date
// as a unix timestamp. It will also always be in the
// ts field.
if (! empty($r[’show_date’])) {
if (‘modified’ == $r[’show_date’])
$page_tree[$page->ID][‘ts’] = $page->post_modified;
else
$page_tree[$page->ID][‘ts’] = $page->post_date;
}
// The tricky bit!!
// Using the parent ID of the current page as the
// array index we set the curent page as a child of that page.
// We can now start looping over the $page_tree array
// with any ID which will output the page links from that ID downwards.
if ( $page->post_parent != $page->ID)
$page_tree[$page->post_parent][‘children’][] = $page->ID;
}
// Output of the pages starting with child_of as the root ID.
// child_of defaults to 0 if not supplied in the query.
$output .= _page_level_out($r[‘child_of’],$page_tree, $r, 0, false);
if ( $r[‘title_li’] )
$output .= ‘</ul></li>’;
endif;
$output = apply_filters(‘wp_list_pages’, $output);
if ( $r[‘echo’] )
echo str_replace(‘/"’,‘.html"’,$output);
else
return $output;
}
and
// global $wp_query;
// $queried_obj = $wp_query->get_queried_object();
$output = ”;
if($depth)
$indent = str_repeat(“\t“, $depth);
//$indent = join(”, array_fill(0,$depth,"\t"));
foreach($page_tree[$parent][‘children’] as $page_id) {
$cur_page = $page_tree[$page_id];
$title = $cur_page[‘title’];
$css_class = ‘page_item’;
if( $page_id == $queried_obj->ID) {
$css_class .= ‘ current_page_item’;
}
$output .= $indent . ‘<li class="’ . $css_class . ‘"><a href="’ . get_page_link($page_id) . ‘" title="’ . wp_specialchars($title) . ‘">’ . $title . ‘</a>’;
if(isset($cur_page[‘ts’])) {
$format = get_settings(‘date_format’);
if(isset($args[‘date_format’]))
$format = $args[‘date_format’];
$output .= ” “ . mysql2date($format, $cur_page[‘ts’]);
}
echo “\n“;
if(isset($cur_page[‘children’]) && is_array($cur_page[‘children’])) {
$new_depth = $depth + 1;
if(!$args[‘depth’] || $depth < ($args[‘depth’]-1)) {
$output .= “$indent<ul>\n“;
$output .= _page_level_out($page_id, $page_tree, $args, $new_depth, false);
$output .= “$indent\n“;
}
}
$output .= “$indent</li>\n“;
}
if ( $echo )
echo $output;
else
return $output;
}
template-functions-general.php (to put blog description in homepage title)
global $wpdb;
global $m, $year, $monthnum, $day, $category_name, $month, $posts;
$cat = get_query_var(‘cat’);
$p = get_query_var(‘p’);
$name = get_query_var(‘name’);
$category_name = get_query_var(‘category_name’);
// If there’s a category
if(!empty($cat)) {
if (!stristr($cat,‘-’)) { // category excluded
$title = get_the_category_by_ID($cat);
}
}
if (!empty($category_name)) {
if (stristr($category_name,‘/’)) {
$category_name = explode(‘/’,$category_name);
if ($category_name[count($category_name)-1]) {
$category_name = $category_name[count($category_name)-1]; // no trailing slash
} else {
$category_name = $category_name[count($category_name)-2]; // there was a trailling slash
}
}
$title = $wpdb->get_var(“SELECT cat_name FROM $wpdb->categories WHERE category_nicename = ‘$category_name’”);
}
// 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”;
}
if (!empty($year)) {
$title = $year;
if (!empty($monthnum)) {
$title .= ” $sep “.$month[zeroise($monthnum, 2)];
}
if (!empty($day)) {
$title .= ” $sep “.zeroise($day, 2);
}
}
// If there’s a post
if (is_single() || is_page()) {
$title = strip_tags($posts[0]->post_title);
$title = apply_filters(’single_post_title’, $title);
}
// Send it out
if ($display && isset($title)) {
echo ” $sep $title”;
} elseif (!$display && isset($title)) {
return ” $sep $title”;
} elseif ($display){
echo ” $sep “;
bloginfo(‘description’);
}
}
I still haven’t gotten round to putting correct titles in the feeds, will post the fuctoin changes when done.
The excellent template I used as a base is Red Train 1.0 by Vladimir Simovic (so a big thanks to Vlad).
I then changed it a bit, here are my blog templates:
style.css
index.php
page.php
comments.php
I also used Owen Winkler’s Code Filter plugin to properly display code, but had to slightly change it to:
{
return “<blockquote{$stuff[1]}>”.htmlspecialchars(clean_pre($stuff[2]), ENT_NOQUOTES).“</blockquote >”;
}
function cf_encode($content)
{
return preg_replace_callback(‘|<blockquote([^>]*)>(.*)</blockquote >|imsU’, ‘cf_callback’, $content);
}
add_filter(‘the_content’, ‘cf_encode’, ‘1′);
Hope this saves someone the couple of days it has taken me to get Wordpress set up properly to my liking