ThemeShaper Forums » Thematic

[closed]

Overwriting Functions

(5 posts)
  • Started 5 years ago by patdryburgh
  • Latest reply from yilmaznakliyat
  • This topic is resolved
  1. Hey Ian,

    I'm currently working on a child theme, and was wondering how to go about overwriting the thematic_postfooter function.

    This is what you have:

    function thematic_postfooter() {
        global $id, $post;
    
        // Create $posteditlink
        $posteditlink .= '<a href="' . get_bloginfo('wpurl') . '/wp-admin/post.php?action=edit&post=' . $id;
        $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
        $posteditlink .= __('Edit', 'thematic') . '</a>';
    
        // Display the post categories
        $postcategory = '<div class="entry-utility">';
        $postcategory .= '<span class="cat-links">';
        if (is_single()) {
            $postcategory .= __('This entry was posted in ', 'thematic') . get_the_category_list(', ');
            $postcategory .= '</span>';
        } elseif ( is_category() && $cats_meow = sandbox_cats_meow(', ') ) { /* Returns categories other than the one queried */
            $postcategory .= __('Also posted in ', 'thematic') . $cats_meow;
            $postcategory .= '</span> <span class="meta-sep">|</span>';
        } else {
            $postcategory .= __('Posted in ', 'thematic') . get_the_category_list(', ');
            $postcategory .= '</span> <span class="meta-sep">|</span>';
        }
    
        // Display the tags
        if (is_single()) {
            $tagtext = __(' and tagged', 'thematic');
            $posttags = get_the_tag_list("<span class=\"tag-links\"> $tagtext ",', ','</span>');
        } elseif ( is_tag() && $tag_ur_it = sandbox_tag_ur_it(', ') ) { /* Returns tags other than the one queried */
            $posttags = '<span class="tag-links">' . __(' Also tagged ', 'thematic') . $tag_ur_it . '</span> <span class="meta-sep">|</span>';
        } else {
            $tagtext = __('Tagged', 'thematic');
            $posttags = get_the_tag_list("<span class=\"tag-links\"> $tagtext ",', ','</span> <span class="meta-sep">|</span>');
        }
    
        // Display comments link and edit link
        if (comments_open()) {
            $postcommentnumber = get_comments_number();
            if ($postcommentnumber > '1') {
                $postcomments = ' <a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">';
                $postcomments .= get_comments_number() . __(' Comments', 'thematic') . '</a>';
            } elseif ($postcommentnumber == '1') {
                $postcomments = ' <a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">';
                $postcomments .= get_comments_number() . __(' Comment', 'thematic') . '</a>';
            } elseif ($postcommentnumber == '0') {
                $postcomments = ' <a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">';
                $postcomments .= __('Leave a comment', 'thematic') . '</a>';
            }
        } else {
            $postcomments = ' <span class="comments-link">' . __('Comments closed', 'thematic') .'</span>';
        }
        // Display edit link
        if (current_user_can('edit_posts')) {
            $postcomments .= ' <span class="meta-sep">|</span> ' . $posteditlink;
        }               
    
        // Display permalink, comments link, and RSS on single posts
        $postconnect .= __('. Bookmark the ', 'thematic') . '<a href="' . get_permalink() . '" title="' . __('Permalink to ', 'thematic') . the_title_attribute('echo=0') . '">';
        $postconnect .= __('permalink', 'thematic') . '</a>.';
        if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) { /* Comments are open */
            $postconnect .= ' <a class="comment-link" href="#respond" title ="' . __('Post a comment', 'thematic') . '">' . __('Post a comment', 'thematic') . '</a>';
            $postconnect .= __(' or leave a trackback: ', 'thematic');
            $postconnect .= '<a class="trackback-link" href="' . trackback_url(FALSE) . '" title ="' . __('Trackback URL for your post', 'thematic') . '" rel="trackback">' . __('Trackback URL', 'thematic') . '</a>.';
        } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) { /* Only trackbacks are open */
            $postconnect .= __(' Comments are closed, but you can leave a trackback: ', 'thematic');
            $postconnect .= '<a class="trackback-link" href="' . trackback_url(FALSE) . '" title ="' . __('Trackback URL for your post', 'thematic') . '" rel="trackback">' . __('Trackback URL', 'thematic') . '</a>.';
        } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) { /* Only comments open */
            $postconnect .= __(' Trackbacks are closed, but you can ', 'thematic');
            $postconnect .= '<a class="comment-link" href="#respond" title ="' . __('Post a comment', 'thematic') . '">' . __('post a comment', 'thematic') . '</a>.';
        } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) { /* Comments and trackbacks closed */
            $postconnect .= __(' Both comments and trackbacks are currently closed.', 'thematic');
        }
        // Display edit link on single posts
        if (current_user_can('edit_posts')) {
            $postconnect .= ' ' . $posteditlink;
        }
    
        // Add it all up
        if ($post->post_type == 'page' && current_user_can('edit_posts')) { /* For logged-in "page" search results */
            $postfooter = '<div class="entry-utility">' . $posteditlink;
            $postfooter .= "</div><!-- .entry-utility -->\n";
        } elseif ($post->post_type == 'page') { /* For logged-out "page" search results */
            $postfooter = '';
        } else {
            if (is_single()) {
                $postfooter = $postcategory . $posttags . $postconnect;
            } else {
                $postfooter = $postcategory . $posttags . $postcomments;
            }
            $postfooter .= "</div><!-- .entry-utility -->\n";
        }
    
        // Put it on the screen
        echo apply_filters( 'thematic_postfooter', $postfooter ); // Filter to override default post footer
    }

    I would like to take this code, rewrite a few bits, and put it in my child theme's functions.php file. Will this cause a problem? Or will it simply overwrite what you have?

    Thanks!

    Posted 5 years ago #
  2. Start with

    function childtheme_postfooter() {
    // Do stuff here
    }
    add_filter ('thematic_postfooter', 'childtheme_postfooter'); // Crazy important!

    You could either copy the contents of my bonkers filter and change a few things or just rewrite it with a few ifs like I did in Custom WordPress Hooks and Filters in Thematic 0.6.

    I find rewriting things easier. You could also just add a filter on single pages by wrapping it in if (is_single()). Or what have you.

    BTW, I have to style the pre element one of these days. Yikes.

    Posted 5 years ago #
  3. Thanks very much, Ian.

    I really hope you'll be impressed with what I'm doing!

    Posted 5 years ago #
  4. spammie
    Member

    i just wanted to update this topic to keep up to date. if you use the solution mentioned here you will have to replace all those old sandbox_cats_meow functions to thematic_cats_meow functions.

    have fun,
    spammie

    Posted 4 years ago #
  5. thank you very much.Very good.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.