WordPress.org

Forums

Simple Fields
how to call an attached image from simple fields (3 posts)

  1. Toby
    Member
    Posted 2 years ago #

    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/

  2. Pär Thernström
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. Toby
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Simple Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.