Advertisement
tpflanz

Latest Posts per Category as Unordered List in Wordpress

Mar 11th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <div class="latest-posts">
  2. <?php
  3. $cat_args=array(
  4.   'include' => '1,2,3,4', // categories to display separated by commas
  5.   'orderby' => 'ID', // ordered by category id - options - ID, name, slug, count, term_group
  6.   'order' => 'ASC' // order ascending
  7.    );
  8. $categories=get_categories($cat_args);
  9.   foreach($categories as $category) {
  10.     $args=array(
  11.       'showposts' => 4, // number of posts to display
  12.       'category__in' => array($category->term_id),
  13.       'ignore_sticky_posts'=>1 // number of sticky posts to ignore in the listing
  14.     );
  15.     $posts=get_posts($args);
  16.       if ($posts) {
  17.         echo '<ul class="preview"><div class="preview-header"><div class="category"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></div></div>';
  18.         foreach($posts as $post) {
  19.           setup_postdata($post); ?>
  20.         <li>
  21.         <div class="image"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'small' ); ?></a></div>
  22.         <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
  23.         </li>
  24.        
  25.           <?php
  26.                 }
  27. echo '</ul>';       }
  28.             }
  29. ?>
  30. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement