• Resolved prodigiworld

    (@prodigiworld)


    HI, really nice plugin.. I installed and it workd as I expected, on your FAQ i saw that there’s a way to call the images using this function..
    $avatar = get_author_image_url()

    Do you think can help to use and integrated this with my themes?

    $first_img = $img_dir . '/images/post-default.jpg';

    Im thinking to show author’s avatar instead post-default.jpg as default if no images on the contents.
    Please find the full script below that exist on my themes, if you can give me direction how to achieves this, it would really helpfull.

    function get_post_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
    
      if(empty($first_img)){ //Defines a default image
        $img_dir = get_bloginfo('template_directory');
        $first_img = $img_dir . '/images/post-default.jpg';
      }
      return $first_img;
    }

    https://www.ads-software.com/extend/plugins/easy-author-image/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lawsonry

    (@lawsonry)

    Prodigiworld,

    Let me see if I’ve got your requirements right:

    The function should do the following:

    • Check to see if a post thumbnail exists
    • If YES, get and return the URL
    • If NO, check to see if the profile image has been uploaded
    • — If YES, get and return the URL
    • — If NO, continue
    • Finally, if neither the post thumbnail or author image is set, get and return the default post image

    Now that we have mapped out our requirements, let’s build the function.

    // Returns the URL of a post image, either the post thumbnail if the post
    function get_post_image() {
    
    	global $post;
    
    	$url = "";
    
    	if(has_post_thumbnail()) { 	// Check to see if a post thumbnail exists
    		$url = get_the_post_thumbnail($post->ID);
    	} else if ( "" != get_the_author_meta('author_profile_picture') { // If there's no post thumbnail, use the author image
    		$url = get_author_image_url();
    	} else {  // No post thumbnail and no author image, so use default image
    		$url = get_bloginfo('template_directory') . "/images/post-default.jpg";
    	}
    
    	return $url;
    }

    Usage:

    // Somehwere in the loop, after while(have_posts()): the_post(); 
    
    <?php $post_image = get_post_image(); ?>
    
    <div class="post-image">
    	<img src="<?php echo $post_image; ?>"/>
    </div>
    <div class="post-title">
    	<h1><?php the_title();?></h1>
    </div>
    <div class="post-content">
    	<?php the_content();
    </div>

    I hope this helps.

    Plugin Author Lawsonry

    (@lawsonry)

    Since this isn’t really a plugin issue, I’m going to mark this topic as resolved. If you have any more template integration problems, please use my support form at lawsonry.com/themes/support.

    Thread Starter prodigiworld

    (@prodigiworld)

    Thank YOU!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Inserted’ is closed to new replies.