Strip Image Attributes from my Variable
-
I posted this in a reply, but thought it needed its only topic.
I’m grabbing the post_thumbnail for a specific post. I’m then trying to display this as the background image for a div. The problem is that the call for the thumbnail also pulls in the width/height and alt tags. Stuff I don’t need (and that throw’s off the inline css). How can I strip that?
<?php $posts=query_posts('page_id=22'); if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $thumbnail = ''; if (function_exists('has_post_thumbnail')) { if ( has_post_thumbnail() ) { $thumbnail = get_the_post_thumbnail($post->ID,'featured'); } } ?> <?php endwhile; endif; ?> <div style="background: url(<?php echo $thumbnail; ?>) no-repeat;> <h3><?php the_title(); ?>:</h3> <h4>Player's Name!</h4> </div>Which outputs this:
<div style="background: url(<img width="292" height="260" src="http://www.mydomain.com/wp/wp-content/uploads/2010/04/player-featured-292x260.jpg" class="attachment-featured wp-post-image" alt="" title="player-featured" />) no-repeat;> <h3>Featured Skater:</h3> <h4>Player's Name!</h4> </div>So if I could just easily strip everything before the http of the image and everything after, I’d be good to go.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Strip Image Attributes from my Variable’ is closed to new replies.