<?php $my_query = new WP_Query('category_name=best&showposts=3'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="thumbnail-featured"><a href="<?php the_permalink() ?>"><img height="60" width="60" style="border: none;" alt="<?php the_title(); ?>" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php echo catch_that_image() ?>&h=60&w=60&zc=1" /></a></div> <div id="featured-content"> <h3 class="best-titles"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <div class="postf"><?php the_content_limit(70, ""); ?></div> </div> <?php endwhile; ?>
<?php echo catch_that_image() ?>
function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //путь к дефолтной картинке $first_img = "default.jpg"; } return $first_img; }
<img height="60" width="60" style="border: none;" alt="<?php the_title(); ?>" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php echo catch_that_image() ?>&h=60&w=60&zc=1" />
Понравилась статья? - Подпишись. Или поделись полезным с миром
<?php the_content_limit(70, ""); ?>
function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content);
if (strlen($_GET['p']) > 0) {
echo "<div>";
echo $content;
echo "</div>";
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "<div>";
echo $content;
echo "...";
echo "</div>";
}
else {
echo "<div>";
echo $content;
echo "</div>";
}
}
.thumbnail-featured {
border: 1px solid #E4E4E4;
float: left;
height: 60px;
padding: 2px;
width: 60px;
}
#featured-content {
float: right;
margin-right: 5px;
width: 170px; /*тут может быть другая ширина в зависимости от ширины сайдбара*/
}
.best-titles {
font-size: 12px;
margin-bottom: 5px;
margin-top: 0;
}
.postf {
border-bottom: 1px dashed #CCCCCC;
font-size: 11px;
margin-top: 0;
padding-bottom: 5px;
}