Posts

Showing posts from June 29, 2010

Display 5 latest posts in each category in WordPress

<div id="page-not-found" class="post-page"> <?php $cat_args = array( 'orderby' => 'name', 'order' => 'ASC', 'child_of' => 0 ); $categories = get_categories($cat_args); foreach($categories as $category) { echo '<dl>'; echo '<dt> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dt>'; $post_args = array( 'numberposts' => 5, 'category' => $category->term_id ); $posts = get_posts($post_args); foreach($posts as $post) { ?> <dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd> } echo '<dd class="view-all"> <a href="' . g

display the_content with setup_postdata

<?php global $more; $cat= 3; $posts = get_posts ("cat=$cat&showposts=5"); if ($posts) { foreach ($posts as $post): $more = false; setup_postdata($post); ?> <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> <p class="storycontent"><?php the_content('Read more...'); ?></p> <?php endforeach; $more = true; } ?>