Support » Plugin: Simple Fields » how to call an attached image from simple fields

  • Hi I am using simple fields to append some extra content to the bottom of posts.

    Here is my code

    //Add Author Box if its entered
    function get_author_box($content) {
    	global $post;
    	//$author_name = simple_fields_get_post_value(get_the_id(), "Author Name", true);
    	//$author_bio = simple_fields_get_post_value(get_the_id(), "Author Bio", true);
    	//$author_pic = simple_fields_get_post_value(get_the_id(), "Author Pic", true);
    	$author_name = simple_fields_value('author_name');
    	$author_bio = simple_fields_value('author_bio');
    	$author_pic = simple_fields_value('author_pic');
    
    	$end_of_content = <<<EOC
    <div class="author_box">
    	<div class="author_pic">
    		<img src="$author_pic" alt="$author_name" />
    	</div>
    	<div class="author_bio">
    		<h4>Written by $author_name</h4>
    		$author_bio
    	</div>
    </div>
    EOC;
    	return ( is_single() ) ? $content . $end_of_content : $content;
    
    }
    add_filter('the_content','get_author_box');

    All is working well except the image returns an array. Can you tell me how I can grab the src url of the thumbnail and display it on the page?

    Thanks
    Toby

    http://wordpress.org/extend/plugins/simple-fields/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Pär Thernström

    (@eskapism)

    if you do this:

    print_r($author_pic);

    you will see what the variable contains, and one of the keys there will contain what you look for.

    Thanks a bunch Par.

    Here’s the code I used to build a small author box that appends to the end of an article.

    //Add Author Box if its entered
    function get_author_box($content) {
    	global $post;
    
    	$author_name = simple_fields_value('author_name');
    	$author_bio = simple_fields_value('author_bio');
    	$author_pic = simple_fields_value('author_pic');
    
    	$end_of_content = <<<EOC
    <div class="author_box">
    	<img src="{$author_pic["url"]}" alt="$author_name" width="100" height="100"/>
    	<div class="author_bio">
    		<h4>Written by $author_name</h4>
    		$author_bio
    	</div>
    </div>
    EOC;
    
    	return ( ( is_single() || is_sticky() ) && simple_fields_value('author_name') == true) ? $content . $end_of_content : $content;
    
    }
    add_filter('the_content','get_author_box');

    I built the image tag myself to control the size of the image on the fly.

    Hope that helps someone.
    Toby

    PS Great plugin dude. Good work going the free route.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to call an attached image from simple fields’ is closed to new replies.