ThemeShaper Forums » Thematic

[closed]

Customizing thematic_postfooter()

(9 posts)
  • Started 9 years ago by WraithKenny
  • Latest reply from ufukerdogmus
  • This topic is not resolved
  1. I checked the wiki, but it didn't have an example on this filter, so I took a stab at it.

    To change the post footer, for example moving the comments text and edit link up to its own line instead of at the end of the tags and categories, you can use the following code:
    function childtheme_postfooter() {
    global $id, $post;

    // Create $posteditlink
    $posteditlink = '<span class="edit"><a href="' . get_bloginfo('wpurl') . '/wp-admin/post.php?action=edit&post=' . $id;
    $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
    $posteditlink .= __('Edit', 'thematic') . '</span>';
    $posteditlink = apply_filters('thematic_postfooter_posteditlink',$posteditlink);

    // Display the post categories
    $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 = thematic_cats_meow(', ') ) { // Returns categories other than the one queried
    $postcategory .= __('Also posted in ', 'thematic') . $cats_meow;
    $postcategory .= '</span> <span class="meta-sep meta-sep-tag-links">|</span>';
    } else {
    $postcategory .= __('Posted in ', 'thematic') . get_the_category_list(', ');
    $postcategory .= '</span> <span class="meta-sep meta-sep-tag-links">|</span>';
    }
    $postcategory = apply_filters('thematic_postfooter_postcategory',$postcategory);

    // 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 = thematic_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 meta-sep-comments-link">|</span>';
    } else {
    $tagtext = __('Tagged', 'thematic');
    $posttags = get_the_tag_list("<span class=\"tag-links\"> $tagtext ",', ','</span>');
    }
    $posttags = apply_filters('thematic_postfooter_posttags',$posttags);

    // Display comments link and edit link
    if (comments_open()) {
    $postcommentnumber = get_comments_number();
    if ($postcommentnumber > '1') {
    $postcomments = ' <span class="comments-link">';
    $postcomments .= get_comments_number() . __(' Comments', 'thematic') . '
    </span>';
    } elseif ($postcommentnumber == '1') {
    $postcomments = ' <span class="comments-link">';
    $postcomments .= get_comments_number() . __(' Comment', 'thematic') . '
    </span>';
    } elseif ($postcommentnumber == '0') {
    $postcomments = ' <span class="comments-link">';
    $postcomments .= __('Leave a comment', 'thematic') . '
    </span>';
    }
    } else {
    $postcomments = ' <span class="comments-link comments-closed-link">' . __('Comments closed', 'thematic') .'</span>';
    }
    // Display edit link
    if (current_user_can('edit_posts')) {
    $postcomments .= ' <span class="meta-sep meta-sep-edit">|</span> ' . $posteditlink;
    }
    $postcomments = apply_filters('thematic_postfooter_postcomments',$postcomments);

    // Display permalink, comments link, and RSS on single posts
    $postconnect .= __('. Bookmark the ', 'thematic') . '';
    $postconnect .= __('permalink', 'thematic') . '
    .';
    if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) { // Comments are open
    $postconnect .= ' ' . __('Post a comment', 'thematic') . '';
    $postconnect .= __(' or leave a trackback: ', 'thematic');
    $postconnect .= '' . __('Trackback URL', 'thematic') . '.';
    } 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 .= '' . __('Trackback URL', 'thematic') . '.';
    } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) { // Only comments open
    $postconnect .= __(' Trackbacks are closed, but you can ', 'thematic');
    $postconnect .= '' . __('post a comment', 'thematic') . '.';
    } 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;
    }
    $postconnect = apply_filters('thematic_postfooter_postconnect',$postconnect);

    // 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">' . '<span class="edit">' . $posteditlink . '</span>';
    $postfooter .= "</div><!-- .entry-utility -->\n";
    } elseif ($post->post_type == 'page') { // For logged-out "page" search results
    $postfooter = '';
    } else {
    if (is_single()) {
    $postfooter = '<div class="entry-utility">' . $postconnect . '

    ' . $postcategory . $posttags;
    } else {
    $postfooter = '<div class="entry-utility">' . $postcomments . '

    ' . $postcategory . $posttags;
    }
    $postfooter .= "</div><!-- .entry-utility -->\n";
    }

    // Put it on the screen
    return $postfooter;
    }
    add_filter('thematic_postfooter', 'childtheme_postfooter');

    I also changed a couple of ".=" to "=" as it looked like a variable declaration, and changed a </span> <span class="meta-sep meta-sep-comments-link">|</span> into </span> as it was no longer needed.

    It seems a bit long, and I was wondering if there's a better/easier way to do this.

    Posted 9 years ago #
  2. Hi,

    give me time 'til Sunday and I have something for you that makes it easier to rearrange thematic_postheader / thematic_postfooter

    Chris

    Posted 9 years ago #
  3. @Chris Any update on an easier way to rearrange this? Thanks

    Posted 9 years ago #
  4. .. will commit the latest changes to the SVN in approx. 1h

    Chris

    Posted 9 years ago #
  5. ok .. uploaded revision 567 to the SVN.

    The following code will display only the title in the post header:

    function my_postheader() {
    
    	$postheader = thematic_postheader_posttitle();
    	return $postheader;
    
    }
    add_filter('thematic_postheader', 'my_postheader');

    Here's the new thematic_postheader function:

    // Information in Post Header
    function thematic_postheader() {
    
        global $post;
    
        if ($post->post_type == 'page' || is_404()) {
            $postheader = thematic_postheader_posttitle();
        } else {
            $postheader = thematic_postheader_posttitle() . thematic_postheader_postmeta();
        }
    
        echo apply_filters( 'thematic_postheader', $postheader ); // Filter to override default post header
    } // end thematic_postheader

    And this is the new thematic_postfooter function:

    // Information in Post Footer
    function thematic_postfooter() {
        global $id, $post;
    
       // Display comments link and edit link
    
        // Display permalink, comments link, and RSS on single posts
    
        // 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">' . '<span class="edit">' . thematic_postfooter_posteditlink() . '</span>';
            $postfooter .= "</div><!-- .entry-utility -->\n";
        } elseif ($post->post_type == 'page') { /* For logged-out "page" search results */
            $postfooter = '';
        } else {
            if (is_single()) {
                $postfooter = '<div class="entry-utility">' . thematic_postfooter_postcategory() . thematic_postfooter_posttags() . thematic_postfooter_postconnect();
            } else {
                $postfooter = '<div class="entry-utility">' . thematic_postfooter_postcategory() . thematic_postfooter_posttags() . thematic_postfooter_postcomments();
            }
            $postfooter .= "</div><!-- .entry-utility -->\n";
        }
    
        // Put it on the screen
        echo apply_filters( 'thematic_postfooter', $postfooter ); // Filter to override default post footer
    } // end thematic_postfooter

    All functions called in thematic_postheader and thematic_postfooter can be filtered. The new code is compatible with all current child themes (still using the same filter names).

    Let me know if this works for you or if we need to break the whole thing into smaller parts.

    Chris

    Posted 9 years ago #
  6. This looks nicer but now, I'm not sure how to filter these? For example how can I remove the "Published:" before the date in the postheader meta section? Should I just unload the function and create mine?

    Posted 9 years ago #
  7. Yes .. you need to filter thematic_postheader_postmeta();

    Chris

    Posted 9 years ago #
  8. Sorry but this is very confusing to me. Basically, now that you replaced the old code given by WraithKenny just on top of this post, could you please give me an example on how to customize the postfooter & postheader ?

    I mean the thematic_postheader_postmeta(); isn't referenced anymore in the content-extensions.php, so I assume if someone new to thematic wants to customize this data, how is he supposed to know that this filter exist? Not to mention how to customize it?

    What I want to do for example, is just remove the "Published" statement before the date, and move the comment count from the postfooter to the postheader meta.

    This seems very simple plus I can see those calls in your new code as "thematic_postfooter_postcomments();". But still I can't figure it out. Could you please show me the way or explain to me the logic that's under it?

    Thanks much.

    Here's what I've got by the way, I removed the Published statement by hand, but I guess there's a better way to do :

    // Filtering the postheader_postmeta
    function my_postheader_postmeta() {
    
        $postmeta = '<div class="entry-meta">';
        $postmeta .= '<span class="meta-prep meta-prep-author">' . __('By ', 'thematic') . '</span>';
        $postmeta .= '<span class="author vcard">'. '<a class="url fn n" href="';
        $postmeta .= get_author_link(false, $authordata->ID, $authordata->user_nicename);
        $postmeta .= '" title="' . __('View all posts by ', 'thematic') . get_the_author() . '">';
        $postmeta .= get_the_author();
        $postmeta .= '</span><span class="meta-sep meta-sep-entry-date"> | </span>';
        $postmeta .= '<span class="meta-prep meta-prep-entry-date">' . __('', 'thematic') . '</span>';
        $postmeta .= '<span class="entry-date"><abbr class="published" title="';
        $postmeta .= get_the_time(thematic_time_title()) . '">';
        $postmeta .= get_the_time(thematic_time_display());
        $postmeta .= '</abbr> | </span>';
    
        $postmeta .= '<span class="cat-links">';
        if (is_single()) {
            $postmeta .= __('', 'thematic') . get_the_category_list(', ');
            $postmeta .= '</span>';
        } elseif ( is_category() && $cats_meow = thematic_cats_meow(', ') ) { /* Returns categories other than the one queried */
            $postmeta .= __(', ', 'thematic') . $cats_meow;
            $postmeta .= '</span> <span class="meta-sep meta-sep-tag-links">|</span>';
        } else {
            $postmeta .= __('', 'thematic') . get_the_category_list(', ');
            $postmeta .= '</span> <span class="meta-sep meta-sep-tag-links">|</span>';
        }
    
        // Display edit link
        if (current_user_can('edit_posts')) {
            $postmeta .= ' <span class="meta-sep meta-sep-edit">|</span> ' . '<span class="edit">' . $posteditlink . '</span>';
        }
        $postmeta .= "</div><!-- .entry-meta -->\n";
        return $postmeta;
    }
    add_filter('thematic_postheader_postmeta','my_postheader_postmeta');
    Posted 9 years ago #
  9. This is an example of how you can do it now:
    I hope you understand it :)

    // create new function to replace old one
    function MY_thematic_postheader_postmeta() {
    //basically copy the original content of the function inside
    $postmeta = '<div class="entry-meta">';
    $postmeta .= thematic_postmeta_authorlink();
    $postmeta .= '<span class="meta-sep meta-sep-entry-date"> | </span>';
    $postmeta .= thematic_postmeta_entrydate();

    $postmeta .= thematic_postmeta_editlink();

    $postmeta .= "</div><!-- .entry-meta -->\n";
    $postmeta .= "LET'S SAY I ADDED THIS LINE";

    return apply_filters('MY_thematic_postheader_postmeta',$postmeta);

    } // end function and put in filter:
    add_filter('thematic_postheader_postmeta','MY_thematic_postheader_postmeta');

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.