Jun15, 2010

Wordpress Child Pages Page... or something

OK, back to srs business posts now...

One of my current top secret projects (it's not that exciting, I'm just helping someone convert their site to WordPress) involves creating pages with a list of child pages on 'em. Back in ye olde days I'd have done this manually (which meant every time a child page was added the parent had to be modified) or farted about with SQL queries but Modern Day WordPress seems to have a function for everything and so it's much simpler. So, without further ado...

Create the template:

<?php
/*
Template Name: Sub Page
*/
?>

<?php get_header(); ?>

<div id="content">

<h2><?php the_title(); ?></h2>

<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) {
?>
<ul>
<?php echo $children; ?>
</ul>
<?php
}

if ($post->post_parent)
echo '<a href="'. get_permalink($post->post_parent) .'">&laquo; Back to '. get_the_title($post->post_parent) .'</a>';
?>


</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Save it as subpage.php, upload it to your theme directory and then whenever you just want a list of sub (child) pages, select Sub Page from the Template dropdown on the right. Ner nerrr!

Tip: if you wanted a section intro instead of just a list of links, bung <?php if ( have_posts() ) { while ( have_posts() ) { the_post(); ?><?php the_content(); ?><?php } } ?> after the h2 title stuff.

Tagged , and .

Apr26, 2010

On Tumblelogs and Why I Love Habari

For at least 4-5 years I've been desperate to turn my blog into a sort of "tumblelog"; that is, a blog that consists of multiple content types that you can easily update with more than just full on text entries. The problem is, at first I lacked the know-how to achieve it — my early blog/CMS was far too primitive and would have been virtually impossible to easily update — and then I flicked back and forth with WordPress which would have required intensive hacking about of an already bloated system.

A few years ago Tumblr came along, providing the theoretical answer to all my prayers... except 3rd party services and I don't get along. I don't trust other people to look after my data. (This is why I don't post anything meaningful to twitter, incidentally.)

Fast-forward to a few months ago, and I was chatting about life streams, tumblelogs, updating websites to the girls on IRC and turns out I wasn't the only one with this goal in mind. Furthermore, as I've converted a few people to Habari lately, we were all singing from the same hymn sheet (what a daft phrase) in terms of CMS, making it easier to come up with a solution that would work for us all.

As it happens, Habari has a content types plugin — created and maintained by the Habari Community, so I know it's secure — which allows me to create custom content types on my blog to allow me to easily post photos, quotes etc with their own styling. Because of Habari's fantastic, simple theming system it's a piece of piss to make it do different things with different post types (no messing with complex PHP, it's as easy as creating a .php file!) This is why I love Habari.