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.

Articles in this series

This entry was posted in Computing, Geeky, Wordpress and tagged , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

6 Comments

  1. Posted February 2, 2009 at 11:11 am | Permalink

    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. Posted February 2, 2009 at 1:59 pm | Permalink

    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!

  3. Posted February 2, 2009 at 2:03 pm | Permalink

    (It was actually add my code before it, but with your principle some variable swapping should be possible)

  4. Posted February 3, 2009 at 10:48 am | Permalink

    Yes. It would be:

    $footer = $extra . $footer;

  5. Posted February 15, 2009 at 10:47 am | Permalink

    It works… now to try and change all those ‘echo’ statements into one big variable!

  6. Posted February 15, 2009 at 12:27 pm | Permalink

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

  • Search

  • Navigation

  • RSS Links

  • What I'm Doing...

    Posting tweet...

  • Recent Comments

  • Categories