ThemeShaper Forums » Thematic

[closed]

Basic Question

(11 posts)
  • Started 4 years ago by iCristiano
  • Latest reply from iCristiano
  • This topic is resolved

Tags:

  1. iCristiano
    Member

    Hi friends,

    Some basic question. I have this code inside a function (on function.php):

    $postmeta = '<div class="post_header">';
    
    $postmeta .= '<div class="author_avatar">';
    $postmeta .= get_the_image(array('widht'=>'85','height'=>'85'));
    $postmeta .= '</div>';
    ...

    Why the image that comes from the "get_the_image" returns out of the <div class="author_avatar"></div>?

    Lets see... if I put this, just to test, the text "something" returns inside the divs:

    $postmeta = '<div class="post_header">';
    
    $postmeta .= '<div class="author_avatar">';
    $postmeta .= 'something';
    $postmeta .= '</div>';
    ...

    But the first code returns something like:

    <a>the image</a>
    <div class="author_avatar"></div>

    Any help???

    Posted 4 years ago #
  2. Hi,

    these are the image script parameters:

    $defaults = array(
    	'custom_key' => array( 'Thumbnail', 'thumbnail' ),
    	'attachment' => true,
    	'default_size' => 'thumbnail',
    	'default_image' => false,
    	'order_of_image' => 1,
    	'link_to_post' => true,
    	'image_class' => false,
    	'image_scan' => false,
    	'width' => false,
    	'height' => false,
    	'echo' => true
    );

    'echo' needs to be set to false.

    Chris

    Posted 4 years ago #
  3. iCristiano
    Member

    Hi Chris!

    I don´t know if its the point... because the image is "printed" the right way, the problem is that it comes outside the <div></div> and it should come inside...

    I got onother exemple:

    $post_avatar = $avtr;
    $postheader_open = '<div class="post_header">';
    $postheader_close = "</div><!-- post_header -->\n";
    
    	if (function_exists('get_avatar')) { // this only fails if pre WP2.5
       	   $avtr = userphoto_the_author_thumbnail('<div class="author_avatar">','</div><!-- .author_avatar  -->');
       			}
    
    	$posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
    
    $my_postheader = $postheader_open . $post_avatar . $posttitle . $postheader_close;
    return $my_postheader;

    In this exemple, the <div class="author_avatar">the avatar</div> comes outside the <div class="post_header"></div>

    I supose it´s the same problem, no?
    Thanks Chris!!!

    Posted 4 years ago #
  4. Hi,

    sorry for the missing explanation. Let's do some basics first.

    Let's say you have a function that constructs a variable that can be filtered. Basically you could break this down to something like:

    echo apply_filters( 'the_filter_hook', 'This is my regular content.'

    Without any filters applied this will display:

    This is my regular content.

    Now we want to filter this content.

    function my_filter($orginal_content) {
        $new_content = $original_content . ' ' . 'get_bloginfo( 'description' );
        return $new_content;
    }
    add_filter( 'the_filter_hook', 'my_filter' );

    get_bloginfo() returns a string.

    This will display:

    This is my regular content. Just another WordPress weblog

    Now let's swap the function get_bloginfo with bloginfo.

    Almost the same thing.

    function my_filter($orginal_content) {
        $new_content = $original_content . ' ' . 'bloginfo( 'description' );
        return $new_content;
    }
    add_filter( 'the_filter_hook', 'my_filter' );

    What's happening now?

    bloginfo() echoes a string. That means, our original function realizes that there's a filter. The filter is called and starts to construct $new_content. Puts $original_content into $new_content. And then bloginfo jumps in and echoes it's data before $new_content is returned and echoed by our original first line of code. So we'll get:

    Just another WordPress weblogThis is my regular content.

    Now back to your two examples:

    The first one is the easy one. get_the_image echoes it's created data by default. Changing your function call to get_the_image(array('width'=>'85','height'=>'85', 'echo'=>false)) will let the function return the data instead of echo the data. And your image will be displayed in the right spot.

    The second one has the same problem. It echoes it's created data, but I don't know if there's an switch to modify this behavior.

    Chris

    Posted 4 years ago #
  5. iCristiano
    Member

    Now I got your explanation! Thanks! :)

    In theory ok, but when I try to use the 'echo'=>false argument, the image disappears...

    What could be happening?

    Posted 4 years ago #
  6. iCristiano
    Member

    I mean, when I use this code, the image jumps out of the <div>:

    if (function_exists('get_the_image')) {
    	$avtr = '<div class="author_avatar">';
       	$avtr .= get_the_image(array('width'=>'85','height'=>'85'));
    	$avtr .= '</div>';
    }
    return $avtr

    And when I use this code, the image disappears:

    if (function_exists('get_the_image')) {
    	$avtr = '<div class="author_avatar">';
       	$avtr .= get_the_image(array('width'=>'85','height'=>'85', 'echo'=>false));
    	$avtr .= '</div>';
    }
    return $avtr
    Posted 4 years ago #
  7. Will test the plugin later this night .. have a Dart Tournament starting in a few minutes :)

    Posted 4 years ago #
  8. iCristiano
    Member

    How was the Dart Tournament? Did you win? :)

    Posted 4 years ago #
  9. The tournament was cool. I was able to throw out a couple of our local 1st league darters. I didn't win the tournament , but the 5th place is pretty good for someone who started to play about 8 month ago :)

    Ok .. back to get_the_image(). I did a test with the following code:

    function test_get_the_image($postmeta) {
    	$avtr = '';
    	if (function_exists('get_the_image')) {
    		$avtr = '<div class="author_avatar">';
    		$avtr .= get_the_image(array('width'=>'85','height'=>'85', 'echo'=>false));
    		$avtr .= '</div>';
    	}
    	return $avtr . $postmeta;
    }
    add_filter( 'thematic_postheader_postmeta', 'test_get_the_image' );

    This will place an image just before the post meta. And the image and the link are place inside of '.author_avatar'. Just as expected.

    If you could pastebin your code and send me a link, I can test it for you.

    Chris

    Posted 4 years ago #
  10. iCristiano
    Member

    Chris, its all right now... the problem was I was using a $post_avatar = $avtr; before... like that:

    function test_get_the_image($postmeta) {
    	$post_avatar = $avtr;
    	if (function_exists('get_the_image')) {
    		$avtr = '<div class="author_avatar">';
    		$avtr .= get_the_image(array('width'=>'85','height'=>'85', 'echo'=>false));
    		$avtr .= '</div>';
    	}
    	return $post_avatar . $postmeta;
    }
    add_filter( 'thematic_postheader_postmeta', 'test_get_the_image' );

    I eliminated it and now is everything ok!

    Let me ask you to take a look in another issue, if you have time:
    http://forums.themeshaper.com/topic/authorphp-x-custom-post-types#post-16815

    Thank you very much!

    Posted 4 years ago #
  11. iCristiano
    Member

    Hey Chris, may you help me with the other issue?
    http://forums.themeshaper.com/topic/authorphp-x-custom-post-types#post-16815

    Sorry for take your time!
    Thanks again!

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.