Thematic – A problem with php

I am working on a Child Theme based on the ‘Thematic‘ framework for WordPress. For more information, see the ‘Murkymatic‘ pages.

In Thematic there is a clever little script in functions.php which goes after every post and displays the tags, categories and so forth. This displays something subtly different on tags pages to category pages and so on. I like it, I want to keep it.

So far, so good. I want to insert into my own function into the child theme after the post but before the post footer.

My function, which is to show related posts if a post is part of a series.

This function works, and works well. Here it is:

function childtheme_article_series() {
    global $id, $post;
    $series = get_post_meta($post->ID, 'Series', true);
    if($series) :
        $args = array(
            'numberposts' => -1,
            'meta_key' => 'Series',
            'meta_value' => $series,
        );
        $series_posts = get_posts($args);
        if($series_posts) :
            $class = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", $series);
            $class = strtolower(str_replace(array(' ', ' '), '-', $class));
            if (is_single()) {
                echo '<div class="series series-' . $class . '"><h4 class="series-title">' . __('Articles in this series') . '</h4><ul>';
                foreach($series_posts as $serial) :
                    if($serial->ID == $post->ID)
                        echo '<li class="current-post">' . $serial->post_title . '</li>';
                    else
                    echo '<li><a href="' . get_permalink($serial->ID) . '" title="' . str_replace('"', '"', $serial->post_title) . '">' . str_replace('"', '"', $serial->post_title) . '</a></li>';
                endforeach;
                echo '</ul></div>';
            } else {
                $pstlink = get_permalink();
                $psttitle = get_the_title();
                echo '<div class="series series-' . $class . '">';
                echo '<h4 class="series-title"><a href="' . $pstlink . '">' . $psttitle . '</a>';
                echo ' is part of a series' . '</h4></div>';
            }
        endif;
    endif;
}

The above code goes into the functions.php of my Child Theme.

The next step is to tell that function when to run, so I hook it into the Thematic hook which is there for that very purpose.

Into my functions.php I add the line: add_action('thematic_postfooter','childtheme_article_series');

Unfortunately, this replaces the existing Thematic footer with my footer. This is not what I want.

In short, I can’t work out how to tell WordPress to run my Child Theme function, then to do the Thematic parent theme function.

I’m at a bit of a loss right now.

I could recreate the existing footer in my routine – but that removes one of the advantages of the child theme, should the Thematic code be updated, my replacement footer would not be.

It is important to be able to over-ride the parent theme’s footer, but it’d be nice to be able to supplement it too. What I want is to tell WordPress to run this function before the thematic_postfooter() function. I don’t want to have to edit Thematic to do this (as this also removes the parent/Child Theme advantage). Though I did try this, and it caused a server 500 error – I have no clue why.

One solution would be if Thematic had a hook before it called thematic_postfooter() which otherwise did nothing – but it doesn’t.

Another solution is if I could work out how to explicitly pass control to the thematic_postfooter() function at the end of my function.

I tried using the information about priorities giving my function a priority of 5, but this didn’t work at all, it still replaced the thematic footer. It seems that sometimes adding an action over-rides, and sometimes it just adds (as expected).

It’s rather a mystery to me right now. It’s something that I think *should* be possible, but I cannot work out how. I’ve left this message on the thematic forums.

I would really appreciate a pointer here, if anyone has a bright idea. The latest murkymatic code can be found on google code.

About Murk

I'm interested in a range of things, from science and computers, to history and creative stuff. I'm leaving a lot out. My problem is time. As a result, murky.org, flits around from topic to topic as my interest is piqued. It's all tagged though - so it should be easy to find other posts of mine on similar topics - do give the RSS feed a try, and I welcome, nay, I crave comments on articles.

6 thoughts on “Thematic – A problem with php

  1. From what I understand, you want to maintain the post footer that Thematic displays and add your code after it (see example)

    This way you get to include the original post footer along with other stuff that you add.

  2. Hmm… thanks for that.

    function my_custom_footer($footer) {

    $extra_stuff = ‘hello world’;

    $footer .= $extra_stuff;

    return $footer;

    }

    I shall have to try it sometime – fingers crossed it’s as simple as it appears!

Leave a Reply