Recent Posts With Thumbnails (Without A Plugin)


  1. создаем функцию генерации новостей с привью-картинками
    function delicious_recent_posts() {
    	$del_recent_posts = new WP_Query();
    	$del_recent_posts->query('showposts=3');
    		while ($del_recent_posts->have_posts()) : $del_recent_posts->the_post(); ?>
    			<li>
    			<?php 
    			if ( has_post_thumbnail() ){
    				$image_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'thumbnail');
    			?> 
    			<a href="<?php the_permalink(); ?>" rel="lightbox">
    				<img class="alignleft img-responsive img-thumbnail" src="<?php echo $image_thumbnail[0]; ?>">
    			</a>
    			<?php
    			}else{
    			?> 
    			<a href="<?php the_permalink(); ?>" rel="lightbox">
    				<img class="img-responsive img-thumbnail" src="/wp-content/uploads/no-image.jpg">
    			</a>
    			<?php
    			}
    			?>
    				<div class="h4">
    					<a href="<?php the_permalink(); ?>">
    						<?php the_title(); ?>
    				   </a>
    				</div>
    			</li>
    		<?php endwhile;
    	wp_reset_postdata();
    }
  2. создаем функцию шорткода по выводу новостей
    function rpt($atts){
    	ob_start();
    	?>
    	<ul class="recent_post_w">
    	<?php
    		echo delicious_recent_posts();
    	?>
    	</ul>
    	<?php
    	$content = ob_get_clean();
    	return $content;
    }
    add_shortcode('rpt', 'rpt');
  3. создаем виджет Recent Posts и используем шорткод [rpt] 🙂
Recent Posts With Thumbnails (Without A Plugin)

Recent Posts With Thumbnails (Without A Plugin)

частично инфа была найдена тут