nakome
7/7/2013 - 3:25 PM

gistfile1.php

<ul class="box">
<?php foreach($posts as $post) { ?>
	<li>
		<?php
                // Get content
                $str = $post['content'];

                // find first img
                preg_match('/<img.+src=[\'"](?P<src>.+)[\'"].*>/i', $str, $img);

                $tumb = UPLOADS.DS.$post['slug'].'.jpg';

                // If have img show this if not show other image
                if(File::exists($tumb)){
                    echo '<img src="'.Option::get('siteurl').'/public/uploads/'.$post['slug'].'.jpg" class="img-post" alt="">';
                }else{
                    // if not get img
                    echo '<img src="'.Option::get('siteurl').'/public/themes/flat-themes/img/img-thumb.png" class="img-post" alt="">';
                }

                // Text count 100 letters
                $str = preg_replace("/<img[^>]+\>/i", "", $str);

            if (strlen($str) > 100){
                echo '<h4>'.$post['title'].'</h4>'.
                substr($str, 0, strpos($str,' ',100)).'...'.Html::br();
            ?>

            <a href="<?php echo Option::get('siteurl');?><?php echo Blog::$parent_page_name; ?>/<?php echo $post['slug'] ?>" class="btn btn-primary">Read More</a>

            <div class="comments-box">
                <i class="icon-comment"></i> <?php echo monstraments::countComments($post['slug']) ?>
            </div>
            <div class="clearfix"></div>

            <?php Html::br(); }else {

                // If have img show this if not show other image
                if(File::exists($tumb)){
                    echo '<img src="'.Option::get('siteurl').'/public/uploads/'.$post['slug'].'.jpg" class="img-post" alt="">';
                }else{
                    // if not get img
                    echo '<img src="'.Option::get('siteurl').'/public/themes/flat-themes/img/img-thumb.png" class="img-post" alt="">';
                }

                echo '<h4>'.$post['title'].'</h4>'.
                     '<p>'.$str.'</p>'.Html::br();

            ?>

                <a href="<?php echo Option::get('siteurl'); ?><?php echo Blog::$parent_page_name; ?>/<?php echo $post['slug'] ?>" class="btn btn-primary">Read More</a>

                <div class="comments-box">
                <i class="icon-comment"></i> <?php echo monstraments::countComments($post['slug']) ?>
            </div>
            <div class="clearfix"></div>

            <?php Html::br(); }?>
    </li>
<?php } ?>
</ul>