ThemeShaper Forums » Thematic

[closed]

Hook for post "entry-content" class?

(8 posts)
  • Started 12 years ago by stonefree
  • Latest reply from helgatheviking
  • This topic is resolved
  1. I'm trying to insert some images at the beginning of every <div class="entry-content"> on all page templates . I couldn't find a hook in the documentation. What is the best way to do this?

    Posted 12 years ago #
  2. middlesister
    Member

    Try filtering thematic_post.

    function childtheme_add_to_content($content) {
        $my_addition = 'image goes here';
        $content = $my_addition . $content;
        return $content;
    }
    add_filter('thematic_post', 'childtheme_add_to_content');
    Posted 12 years ago #
  3. +1 for middlesister's solution

    Posted 12 years ago #
  4. PMix
    Member

    I would like to do essentially the same thing except I want to display the featured image for the post. When I use this code:

    `function childtheme_feature_image($content) {
        	$my_addition = '<div id="inside-post-thumbnail">
    				<?php the_post_thumbnail(\'medium\');?>
    			</div>';
        	$content = $my_addition . $content;
        	return $content;
    }
    add_filter('thematic_post', 'childtheme_feature_image');

    Wordpress doesn't end up running the php code to display the thumbnail image. The html outputs as

    <div id="inside-post-thumbnail">
    <!--?php the_post_thumbnail('medium');?-->
    </div>

    What do I do to get it to execute that line of php code?

    Posted 11 years ago #
  5. when using filters you must not use code that ECHOS, you must RETURN values. the_post_thumbnail echoes. you are also weirdly shifting back and forth between html and php when you are trying to set your variable.

    try :

    function childtheme_feature_image($content) {
            global $post;
        	$my_addition = '<div id="inside-post-thumbnail">. get_the_post_thumbnail($post->ID,'medium') .'</div>';
        	$content = $my_addition . $content;
        	return $content;
    }
    add_filter('thematic_post', 'childtheme_feature_image');

    most WP functions that echo something have a sister function that gets the value instead, for use w/ filters

    http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

    Posted 11 years ago #
  6. PMix
    Member

    I think the $my_addition line needs to be

    $my_addition = '<div id="inside-post-thumbnail"> . get_the_post_thumbnail($post->ID,\'medium\') . </div>';

    but using that just outputs ". get_the_post_thumbnail($post->ID,'medium') ." inside the div tags.

    Posted 11 years ago #
  7. PMix
    Member

    For whatever reason

    function childtheme_feature_image($content) {
            global $post;
        	$my_addition = get_the_post_thumbnail($post->ID,'medium');
        	$content = $my_addition . $content;
        	return $content;
    }
    add_filter('thematic_post', 'childtheme_feature_image');

    works. I can just style with the img tags instead of using the div tags.

    Thanks so much for your help.

    Posted 11 years ago #
  8. it was because you were escaping the ' where you didn't need to escape them.... \'medium\' instead of 'medium'

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.