
Custom loop
By:
carletto0282 on
Nov 16th, 2011 | syntax:
None | size: 0.78 KB | hits: 22 | expires: Never
function loop_news(){
// The News Query
$args = array(
'posts_per_page' => 3,
'post_type' => 'post',
'category_name' => 'news',
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish' );
$loop_news = new WP_Query( $args );
if ( have_posts() ) :
echo '<ul>';
// The Loop
while ( $loop_news->have_posts() ) : $loop_news->the_post();
?>
<li>
<a href="<?php echo the_permalink(); ?>" title="<?php echo the_title_attribute(); ?>">
<?php echo the_title(); ?>
</a>
</li>
<?php
endwhile;
echo '</ul>';
else:
?>
<ul>
<li><p>Sorry, no news at the moment.</p><li>
</ul>
<?php
endif;
// Reset Post Data
wp_reset_postdata();
}