Don't like ads? PRO users don't see any ads ;-)
Guest

Custom loop

By: carletto0282 on Nov 16th, 2011  |  syntax: None  |  size: 0.78 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function loop_news(){
  2.         // The News Query
  3.                 $args = array(
  4.                         'posts_per_page'  => 3,
  5.                         'post_type'       => 'post',
  6.                         'category_name'   => 'news',
  7.                         'orderby'         => 'date',
  8.                         'order'           => 'DESC',
  9.                         'post_status'     => 'publish' );
  10.                                                        
  11.         $loop_news = new WP_Query( $args );
  12.                                
  13.         if ( have_posts() ) :
  14.                                
  15.                 echo '<ul>';
  16.                                
  17.         // The Loop
  18.                 while ( $loop_news->have_posts() ) : $loop_news->the_post();
  19.  
  20.                 ?>
  21.                 <li>
  22.                 <a href="<?php echo the_permalink(); ?>" title="<?php echo the_title_attribute(); ?>">
  23.                 <?php echo the_title(); ?>
  24.                 </a>
  25.                 </li>                                  
  26.         <?php
  27.                 endwhile;
  28.                 echo '</ul>';
  29.                 else:
  30.                 ?>
  31.                 <ul>
  32.                         <li><p>Sorry, no news at the moment.</p><li>
  33.                 </ul>                  
  34.                 <?php
  35.                 endif;
  36.                        
  37.         // Reset Post Data
  38.         wp_reset_postdata();           
  39.                 }
  40.