first image in post problem
-
hello guys, i want todisplay in index only the firdt image in post, i`ve tried a lots of plugins and hacks but nothing seems to get the job like i want until i found this
// Retrieve the src of first image in a post
function bm_extract_string($start, $end, $original) {
$original = stristr($original, $start);
$trimmed = stristr($original, $end);
return substr($original, strlen($start), -strlen($trimmed));
}
function getFirstImage() {
$content = get_the_content();
$pic_string = bm_extract_string(‘src=”‘,'” ‘,$content);
$imagesize = getimagesize($pic_string);
list($width, $height, $type, $attr) = getimagesize($pic_string);
$link = get_permalink();
$title = get_the_title($post->post_title);
echo ‘‘;
}`<?php getFirstImage(); ?>
it works fine, i even modified a little bit to resize my images
$width = '225'; $height = '140'; echo '<a href="'.$link.'" style="background:url('.$pic_string.'); display:block; width:'.$width.'px; height:'.$height.'px;" title="'.$title.'"></a>'; }
now for the hard part, i want to change the permalink, so when you click on the image to show u the full image … i`ve tried get_image_url(), not working, so … any ideas ??
- The topic ‘first image in post problem’ is closed to new replies.