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?
ThemeShaper Forums » Thematic
Hook for post "entry-content" class?
(8 posts)-
Posted 12 years ago #
-
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 # -
+1 for middlesister's solution
Posted 12 years ago # -
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 # -
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 # -
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 # -
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 # -
it was because you were escaping the ' where you didn't need to escape them.... \'medium\' instead of 'medium'
Posted 11 years ago #
Topic Closed
This topic has been closed to new replies.