Archive for the ‘programming’ Category

Wordpress - Name of Parent Page

Saturday, April 14th, 2007

I’ve just switched my blog to Wordpress 2.1.3 and moved all the expatrick.com content into it. I’m very happy so far - building this theme was straightforward and there were no strange hiccups.

One issue I did encounter is that, while Wordpress gives you a simple system for page hierarchy, it doesn’t give you access to the name of the parent page, just the id of the parent page. Because my header image is based on the title of the section (navbar_lowercaseversionofsectionname) I found that it broke when I added sub-pages to my About page.

This is fine, Wordpress is a nice lightweight CMS, and I was happy to find that is has a nice little system for submitting a custom SQL query to its database and returning the results all in a nice little object. After a short inspection of the table structureI came up with this for my navbar which changes based on section name:

<img src=“<? bloginfo(’template_url’); ?>/images/navbar_<?
if (is_page()) {
        if (!empty($post->post_parent)) {
        $extradata = $wpdb->get_row(”
select post_title from wp_posts where ID = ” . $post->post_parent);
        echo strtolower($extradata->post_title);
        } else {
     echo strtolower($post->post_title);
        }
} else {
        echo “
blog“;
}
?>.gif”
>