ThemeShaper Forums » Thematic

[closed]

Editing Entry Meta & Post Utility Items

(19 posts)
  • Started 4 years ago by sfrangos
  • Latest reply from iCristiano
  • This topic is resolved
  1. Hi -

    I need to edit both the entry Meta items and the post utility items in more ways than CSS allows. Saw the post on CSS fixes (thanks). Also saw a post about moving some functions for these items into the child theme meta functions to edit there (thanks Chris). Had problems with it though.

    • I have prepared a visual to show a before and after of what is needed here: Visual example
    • Chris's earlier explaination is here (for reference). Problem is after copying and pasting it into the Child Theme functions, I see code at top of page.
    • Note that the fix requires both adding icons, and also HTML code (ie. for a line break, etc.) in those locations
    • I believe in rewarding the good help here, so a $25 Amazon gift certificate goes to the solution provider who posts it here within 2 hours. $20 within 3 hours.

      Thanks -
      Scott

    Posted 4 years ago #
  2. Hi -

    One update... I am using the "Avatars" plugin, and must be able to show the author's custom avatar (a photo) in the meta location by inserting this code:
    <?php $avtr = get_avatar(id [, size [, default-image-url]]); echo $avtr; ?>

    I assume it will be inserted in the functions file too, but am not sure how to do it.

    Your help is appreciated.

    - Scott

    Posted 4 years ago #
  3. function my_postheader_postmeta() {
        global $id, $post, $authordata;
    
        if (function_exists('get_avatar')) {
        	$avtr = get_avatar();
        } else {
        	$avtr = '<img alt="default avatar" src="http://bit.ly/2yYpZc"/>';
        } 
    
        $postmeta = '<div class="entry-meta">';
        $postmeta .= $avtr;
        $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 .= '</a></span>';
        $postmeta .= '<img alt="calendar icon" src="http://magpub.com/wp-content/themes/edadv_template/images/calendar.png"/>';
        $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>';
        // Display edit link
        if (current_user_can('edit_posts')) {
            $postmeta .= '<span class="edit">' . $posteditlink . '</span>';
        }
        $postmeta .= "</div><!-- .entry-meta -->\n";
        return $postmeta;
    }
    add_filter('thematic_postheader_postmeta','my_postheader_postmeta');

    Problem was you didnt need the $postmeta = apply_filters('thematic_postheader_postmeta',$postmeta);
    instead you needed to return $postmeta; Tthat is my avatar as the default fall-back image if the plugin fails so replace it with your default.

    - Gene

    Posted 4 years ago #
  4. Hi Scott,

    which additional CSS markup do you need? :)

    Chris

    Posted 4 years ago #
  5. @Gene .. you're right.

    Posted 4 years ago #
  6. Think it would be a good solution to create something like this:

    <div class="author_avatar">
            ... the author's avatar
        </div>
    
        <div class="post_header">
            ... the post title
            ... By author
            ... Icon date edit-link
        </div>

    With this markup you could use floats to mount the avatar and the post header containing the title and the meta information side by side.

    Posted 4 years ago #
  7. Chris & Gene -

    Thanks. One last tweak -- displaying specific avatars for each author. As I read the directions for the special avatar plugin, we may have to get creative with how it goes into the functions file:
    * Just put the plug-in into your plug-in directory (if this doesn’t make sense it probably isn’t something you should be trying :-) ) and activate it.
    * Use the form, Users » Avatars, to define any local avatars for your users. Specify the URI for an avatar image, something like http://your.domain/avatars/image.jpg, where avatars is a directory containing your local images.
    * Also you may set a default size (in pixels) for avatars and define a default image (e.g. http://your.domain/avatars/default.jpg) to use when no local or global avatar is available.
    * The code to include in your template files is documented on the Users » Avatars page too. To start with try:
    o Put get_avatars($comment); inside the comments loop of your comments.php template file to show the comment author’s avatar.
    o Put get_avatar($post->post_author); in your single.php template file to show the post author’s avatar. You’ll need to declare global $post; in the file too.
    * Make use of this feature to generate a unqiue Wavatar (other options exist).

    Full instructions about plugin is here: http://www.sterling-adventures.co.uk/blog/2008/03/01/avatars-plugin/">

    Thanks -
    Scott

    Posted 4 years ago #
  8. Chris is right about the change in markup. To bring the avatar up beside the title you want markup as he laid out.

    function my_postheader_posttitle() {
       global $post;
    
       if (function_exists('get_avatar')) { // this only fails if pre WP2.5
       		$avtr = get_avatar($post->post_author);
       	}
       		$post_avatar = '<div class="author_avatar">';
            $post_avatar .= $avtr;
    		$post_avatar .='</div><!-- .author_avatar  -->';
    
        	$posttitle = '<div class="post_header">';
           if (is_single() || is_page()) {
            $posttitle .= '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
        } elseif (is_404()) {
            $posttitle .= '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
        } else {
            $posttitle .= '<h2 class="entry-title"><a href="';
            $posttitle .= get_permalink();
            $posttitle .= '" title="';
            $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
            $posttitle .= '" rel="bookmark">';
            $posttitle .= get_the_title();
            $posttitle .= "</a></h2>\n";
    
        }
    
        $my_postheader_open = $post_avatar . $posttitle;
        return $my_postheader_open;
    }
    add_filter('thematic_postheader_posttitle','my_postheader_posttitle');
    
    function my_postheader_postmeta() {
        global $id, $post, $authordata;
    
        $posteditlink .= '<a href="' . thm_bloginfo('wpurl', FALSE) . '/wp-admin/post.php?action=edit&amp;post=' . $id;
        $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
        $posteditlink .= __('Edit', 'thematic') . '</a>';
        $posteditlink = apply_filters('thematic_postheader_posteditlink',$posteditlink); 
    
        $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 .= '</a></span>';
        $postmeta .= '<img alt="calendar icon" src="http://magpub.com/wp-content/themes/edadv_template/images/calendar.png"/>';
        $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>';
        // Display edit link
        if (current_user_can('edit_posts')) {
            $postmeta .= '<span class="edit">' . $posteditlink . '</span>';
        }
        $postmeta .= "</div><!-- .entry-meta -->\n";
    
        $postheader_close = "</div><!-- .post_header -->\n";
    
        $my_postheader_close = $postmeta . $postheader_close;
        return $my_postheader_close;
    }
    add_filter('thematic_postheader_postmeta','my_postheader_postmeta');

    and then basic style:

    .author_avatar, .post_header {float:left}
    .entry-content {clear:left}

    The plugin works well with this code on index, single etc. and degrades gracefully as it is only a filter of a WP function. There are no issues with thematics comments area pulling the local avatars either. This effect is on pages also not sure if that is a desired effect.

    Posted 4 years ago #
  9. Heads up... I've gotten into the habit of copying my code after posting here and retesting locally to make sure all is well. This go round no so much.
    Either I'm going mad or the forum is stripping < b r / >'s I've included spaces so it wouldn't get stripped this time. In both code snippets above a < b r / > went missing.
    It is quite possible I've gone mad.

    So where you see $postmeta .= '</a></span>'; you need to change to $postmeta .= '</a></span>< b r / >'; dont for get to remove the spaces.

    Posted 4 years ago #
  10. Ok messing with editing I figured it out it if you have a <br /> in backticks and save the comment and then view the comment you'll notice a space is added between the br and the /

    And if you then come back and edit the comment it is at that point the <br /> is stripped.

    Posted 4 years ago #
  11. sreiwitch
    Member

    Hi,

    This is terrific and almost exactly what I'm trying to do. Thanks for the overall solution! I'm having trouble with one detail though and hoping for some help :)

    I'm also using the local avatar plugin and have successfully implemented the solution above, but would like to preserve the standard functionality on the author archive and category archive pages (all posts by author) so that the author avatar and bio only appear once at the top of those two page types, not repeatedly (which is what they do after adding the functions above). I've tried to do this for the author page using:

    if (is_author()) {
    return FALSE;
    }

    as in:

    <?php
    function my_postheader_posttitle() {
       global $post;
    
       if (function_exists('get_avatar')) { // this only fails if pre WP2.5
       		$avtr = get_avatar($post->post_author);
       	}
       		$post_avatar = '<div class="author_avatar">';
            $post_avatar .= $avtr;
    		$post_avatar .='</div><!-- .author_avatar  -->';
    
    // Remove avatar/author info from author page.
    if (is_author()) {
    return FALSE;
    }
    
       	$posttitle = '<div class="post_header">';
           if (is_single() || is_page()) {
            $posttitle .= '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
            }
        elseif (is_404()) {
            $posttitle .= '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";  
    
        } else {
            $posttitle .= '<h2 class="entry-title"><a href="';
            $posttitle .= get_permalink();
            $posttitle .= '" title="';
            $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
            $posttitle .= '" rel="bookmark">';
            $posttitle .= get_the_title();
            $posttitle .= "</h2>\n";
    
        }
    
        $my_postheader_open = $posttitle . $post_avatar;
        return $my_postheader_open;
    }
    add_filter('thematic_postheader_posttitle','my_postheader_posttitle');
    
    function my_postheader_postmeta() {
        global $id, $post, $authordata;
    
        $posteditlink .= '<a href="' . thm_bloginfo('wpurl', FALSE) . '/wp-admin/post.php?action=edit&amp;post=' . $id;
        $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
        $posteditlink .= __('Edit', 'thematic') . '';
        $posteditlink = apply_filters('thematic_postheader_posteditlink',$posteditlink); 
    
        $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();
        //if ( !(''== $authordata->user_description) ) : echo apply_filters('archive_meta', $authordata->user_description); endif;
        $postmeta .= '</a >< br/>';
        $postmeta .= $authordata->user_description;
        $postmeta .= '</span>< br/>';
        // don't want the calendar icon. $postmeta .= '<img alt="calendar icon" src="http://magpub.com/wp-content/themes/edadv_template/images/calendar.png"/>';
        $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>';
        // Display edit link
    
    // Remove avatar/author info from author page.
        if (is_author()) {
    	return FALSE;
    	}
    
        if (current_user_can('edit_posts')) {
            $postmeta .= '<span class="edit">' . $posteditlink . '</span>';
        }
        $postmeta .= "</div><!-- .entry-meta -->\n";
    
        $postheader_close = "</div><!-- .post_header -->\n";
    
        $my_postheader_close = $postmeta . $postheader_close;
        return $my_postheader_close;
    }
    add_filter('thematic_postheader_postmeta','my_postheader_postmeta');
    ?>

    This does work to get rid of the avatar and author bio on the author page entirely, but I'm trying to simply suppress the function on the author and category "all posts by author" pages so that it will pick up the standard behavior previous to adding these functions. It used to just show the avatar and bio once on the top of the author page, right below the "Author Archives: Author". How would I bring that back and also have it show up that same way on the category "all posts by author" pages?

    By the way, the forum stripped my tags and my tag as well so those need to have spaces removed.

    Thanks in advance for your assistance.

    I'm loving making my own child theme!

    Sarah Reiwitch

    Posted 4 years ago #
  12. Hi Sarah,

    You just need to adjust the child theme's filter function to return the parents original output for author archives.

    function my_postheader_posttitle($parent_content) {

    Starting the function like this will store the parent theme's output in a variable ($parent_content) so later on you can choose to return that original unaltered content like this:

    if (is_author()) {
    return $parent_content;
    }

    Btw, I think I've returned your post's code back to a viable state.

    Cheers,
    Gene

    Posted 4 years ago #
  13. sreiwitch
    Member

    Hi Gene,

    Thanks so much for your reply. In my code above I've modified the functions as you advised:

    function my_postheader_posttitle($parent_content)

    function my_postheader_postmeta($parent_content)

    Then I modified my if statements above about the author pages:

    if (is_author()) {
    return $parent_content;
    }

    But it still looks the same as it did with my original code above. There's still no author image or info at the top of the author archive pages. Am I missing something?

    Thank for fixing my code in the post above and for your help with this. I really appreciate it.

    Sarah

    Posted 4 years ago #
  14. Hi Sarah,

    I think i'm misunderstanding what you mean by standard functionality in:

    preserve the standard functionality on the author archive and category archive pages

    I believe the code I gave you above restored the standard functionality of Thematic's original postheader_postmeta and my_postheader_posttitle functions.

    Are you saying that you want the avatar of the Author listed at the top of the Author archive near the <h1 class="post-title author"> ? And do you want the avatars plugin to provide the avatar or WordPress' default avatar / gravitar behavior?

    -Gene

    Posted 4 years ago #
  15. sreiwitch
    Member

    Hi Gene,

    The standard author bio and local avatar are working now. Sorry, my mistake. I forgot that earlier I had removed from author.php the code for pulling in author avatar/bio due to it showing at the page top and again in each post on the author page. I restored the code and it's showing fine now. Thanks!

    The next thing I’m trying to do is to have two versions of the avatar, one large that would display in the sidebar on a page where someone will input a large bio about the author (bio page) and the one that I'm currently using for the avatar (the large image would be on an actual page that I make, not the author’s post page). This is an example of what I'd like to do:

    http://thewinger.com/patricio-melo/

    There are two issues, how to get the author avatar in the sidebar dynamically based on either the page’s correspondence to the author name and how to have multiple sizes of the image.

    I have tried unsuccessfully to put an author avatar in the sidebar. I installed the widget logic plugin, thinking that would give me some leverage, but that didn’t work either.

    I just started researching this and noticed that the example website is using a different plugin called user photo:

    http://wordpress.org/extend/plugins/user-photo/

    That creates different sizes of an uploaded author image, but now that the author avatar plugin is working and the calls placed within the functions neatly, I'm hesitant to change. I'm not sure how to integrate the new plugin's stuff into the function file. Currently reading about action hooks, but not yet up to speed.

    I would like your advice. Would it be easier to modify what I'm currently using with the local avatar plugin--to get it into the sidebar and to have a larger image appear there or should I start from scratch with the user photo plugin? Worst case scenario is to simply build each bio page, remove sidebar for those pages and stick the corresponding large author image there float right. Not at all dynamic and would be more work each time a new author is added, but it would work. What do you think?

    Thanks!
    Sarah

    Posted 4 years ago #
  16. The local avatars plugin does not look like it can display multiple sizes. Using more than one plugin seems unnecessary.

    I think it could be done one of two ways. They're just hunches, really.

    1. using the avatars plugin with a larger sized author avatar that is sized down for all but the author archive. My best guess is that this could be done by using PHP and str_replace to rewrite the avatar function output to limit the size using the img tag. This method would be the most dynamic and easiest to maintain.

    or

    2. Use the author specific body class to insert a background image of the large author photo into the primary aside for author archives and pad the top to allow the image to show without text overlaying it.

    -Gene

    Posted 4 years ago #
  17. sreiwitch
    Member

    Hi Gene,

    I like the first option you gave and will pursue that one. Thanks for your input and for steering me in a good direction. If I come up with something good I'll post it back here in case someone else would want to use it.

    Sarah

    Posted 4 years ago #
  18. acts7
    Member

    @em hr
    Just a quick note - there's a missing line in the

    function my_postheader_posttitle() {
    global $post;

    ....
    $posttitle = '<div class="post_header">';
    if (is_single() || is_page()) {
    $posttitle .= '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
    // YOU NEED TO CLOSE OUT THE DIV HERE BECAUSE THE META IS NOT CALLED ON PAGES
    // Here is the additional line of code needed:
    $posttitle .= "</div><!-- .post_header -->\n";

    } elseif (is_404()) {
    ....

    Hopefully that will keep anyone else from having to comb over their code to figure why the sidebar was wrapping under comments.

    Posted 3 years ago #
  19. iCristiano
    Member

    Hi friends,
    Thanks for this topic! It helped me a lot!

    I have a curious issue... I had used the script Gene published and almost everything is ok... but some strange thing is happen:

    On my "post-meta", the links (authors and edit) don´t function on the single post... and on the archive´s page, the first one don´t function, but the next are ok! So, I suppose the problem is with the first post on the looping. If there is just one, it doesn´t work, if there are more than one, just the first doesn´t work...

    Strange, right? Any idea?
    Take a look: http://www.caramure.com.br/artigos/

    Thanks!!!

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.