Use Author Image as Featured Image

Home Forums Calendar Products Events Calendar PRO Use Author Image as Featured Image

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #963078
    Chetan
    Participant

    Hi,

    Usually I can see a featured image in my calendar for each event, however, sometimes users do not upload featured images. In such a scenario, I would like to show the event’s author’s image as a featured image. I’m currently using the Divi theme (Version: 2.3.1.).

    I found a file by the name (epanel/custom_functions.php) which has the following code:

    /*this function allows users to use the first image in their post as their thumbnail*/
    if ( ! function_exists( ‘et_first_image’ ) ){
    function et_first_image() {
    global $post;
    $img = ”;
    $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches);
    if ( isset($matches[1][0]) ) $img = $matches[1][0];

    return trim($img);
    }
    }

    Is there a way to mention IF no first image, then show author’s image?

    Thanks~

    #963277
    Geoff
    Member

    Hi there, Chetan!

    Sure, I think that would be totally possible using theย get_avatar() function in an if/else statement like that.

    I’m not quite sure if that snippet you shared has an impact on Events posts. However, the calendar template does call for the featured image, so you could add the conditional if/else statement directly to the template instead. So, something like:

    <?php
    if ( has_post_thumbnail() ) {
    echo tribe_event_featured_image( $event_id, 'full', false );
    }
    else {
    echo get_avatar();
    }
    ?>

    You can also check out our Themer’s Guide for more details on how to override calendar templates.

    Does that help you get started? Please let me know. ๐Ÿ™‚

    Cheers!
    Geoff

    #966407
    Geoff
    Member

    Hello Chetan! This thread’s been quiet for a couple of weeks, so I’m going to go ahead and close it. Please feel free to start a new thread if you still have any questions about fetching the user avatar and we’d be happy to help you there. ๐Ÿ™‚

    Cheers!
    Geoff

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Use Author Image as Featured Image’ is closed to new replies.