• Resolved thisisedie

    (@thisisedie)


    What I’d like to do is makes the background on different author posts different colors. I can do this for author comments but can’t figure out how to do it for author posts. Anyone have any ideas? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • if your theme is using post_class() in the div that contains the post, you can add an author class to it by adding this code to functions.php of your theme:

    //add an author class to post_class() by filter//
    function post_author_id_class($classes) {
    	    global $post;
    	    $classes[] = 'author-'.get_the_author_meta('user_nicename');
    	    return $classes;
    	}
    add_filter('post_class', 'post_author_id_class');

    and then, for instance, style with:
    .author-admin { background: #123456; }

    if your theme does not use post_class(), you might need to edit the template files where you want to show this different background (index.php, single.php, ..) and find the div that surrounds the posts;

    simple example:
    <div class="post" id="post-<?php the_ID(); ?>">

    to include an author class, you could change it to:
    <div class="post<?php echo ' author-' . get_the_author_meta('user_nicename'); ?>" id="post-<?php the_ID(); ?>">

    details depend on your theme; for more help, a link to your site is needed.

    Thread Starter thisisedie

    (@thisisedie)

    Thank you SO much, that worked perfeftly :o)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Author Highlight’ is closed to new replies.