I have done some modification for the current theme home page. I am showing the content till the Read More.. The problem what I was facing was the size of the images. I have written a function which resizes the image according to the image page design. We do not need to bother about the size of the image when we do the post.
First We need some function to find the height and width of the posted image and then resize the image according the size ratio so that images don’t look odd.
function getImageInfo($str, $strfindwhat) {
$widthPos = strpos($str, $strfindwhat);
//echo "Width Position : ".$widthPos;
$strAfterWidth = substr($str, $widthPos);
//echo "After Width : ".$strAfterWidth;
$afterWidthSpace = strpos($strAfterWidth, " " );
$withInfo = substr($strAfterWidth,0, $afterWidthSpace);
//echo " Width Info : ".$withInfo;
$finalWidth= preg_replace("#[^0-9]#", "", $withInfo);
//" ,"" , $withInfo);
return $finalWidth;
}
Then we modify the content using the following function
function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content('');
$content = apply_filters('the_content', $content);
//$content = the_content_limit(100, "Read more");
$thisimageheight = getImageInfo($content, "height");
$thisimagewidth = getImageInfo($content, "width");
if ($thisimagewidth>100) {
$fwidth = 100;
$adjuster = $thisimagewidth / $fwidth;
$fheight = $thisimageheight / $adjuster;
$thisimageheight = $fheight;
$thisimagewidth = $fwidth;
}
$content = str_replace(']]>', ']]>', $content);
$content = str_replace('img', 'img width='.$thisimagewidth.'px height = '.$thisimageheight.'px ', $content);
//$content = strip_tags($content, "<img><b><strong><i><em><a><li><div>");
echo $content;
}
Now we call this function to print the modified content
<div class="grid_5">
<?php query_posts('cat=12,-29,-44&showposts=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="moreinfo">
<h3><?php the_title(); ?></h3>
<p style="font-size:9px; font-weight:200;"><?php the_time('F j, Y'); ?> by <?php the_author_posts_link(); ?> · <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?> <?php edit_post_link('(Edit)', '', ''); ?></p>
<?php the_content_limit(150, ""); ?>
<div style="font-size:9px; font-weight:200;">
Filed Under: <?php the_category(', ') ?><br />Tagged: <?php the_tags('') ?>
</div>
<p class="more"><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">Read More..</a></p>
</div><!-- /moreinfo -->
<?php endwhile; endif; ?>
</div>
I am using the VibrantCMS theme

