ThemeShaper Forums » Thematic

[closed]

Adding Gravar to Posts

(6 posts)
  • Started 3 years ago by RedStarWeb
  • Latest reply from RedStarWeb
  • This topic is not resolved
  1. RedStarWeb
    Member

    I would like to add author gravatar to all my posts, but I'm having a hard time finding a way to do this. I assume I need to filter the post meta data, but I'm not sure where to start.

    Posted 3 years ago #
  2. try reading the primer i just wrote for someone else on how to add things to hooks and how to filter things

    http://forums.themeshaper.com/topic/need-help-understanding-actions-vs-filters-and-changing-post-meta-and-utility#post-22638

    Posted 3 years ago #
  3. RedStarWeb
    Member

    Fantastic resouce, Helga. I think I'm on the right track, but I'm missing something. Here's what I've got right now:

    // Add Author Gravatar to Posts

    function author_gravatar() {
    return '$postmeta' . 'echo get_avatar($author_email, '80')';
    }
    add_filter('thematic_postheader' . 'author_gravatar');

    Posted 3 years ago #
  4. RedStarWeb
    Member

    Okay, I've got it displaying now. I still need to fiddle with styling, and figure out how to keep it from displaying on pages, but if anyone's interested here's what I did:

    // Add Author Gravatar

    function author_gravatar($postmeta) {
    $author_avatar = get_avatar( get_the_author_email(), '80' );
    $postmeta .= $author_avatar;
    return $postmeta;
    }

    add_filter('thematic_postheader', 'author_gravatar');

    Posted 3 years ago #
  5. glad that helped.

    to not display on pages simply wrap the insides w/ a conditional tag

    is_page() test for whether it is a page or not
    ! makes it negative.... so NOT a page.

    codex.wordpress.org/Conditional_Tags

    function bacon(){
      if(!is_page(){
        echo "sooo not a page. let's have bacon";
      }
    }
    add_action('thematic_before','bacon');
    Posted 3 years ago #
  6. RedStarWeb
    Member

    Very helpful! Now I just need to find the best way to style it. Wrapping the avatar in a div seems to work, but it seems like there's probably a better way of doing it.

    Current output:

    // Add Author Gravatar to Posts

    function author_gravatar($postmeta) {
    $author_avatar = '<div class="author-avatar">'; // Trying to format the image by containing it in a div. Not sure if thats the right move.
    $author_avatar .= get_avatar( get_the_author_email(), '80' );
    $author_avatar .= '</div>';
    if(!is_page() ) {
    $postmeta .= $author_avatar;
    }
    return $postmeta;

    add_filter('thematic_postheader', 'author_gravatar');
    }

    add_filter('thematic_postheader', 'author_gravatar');

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.