WordPress Using get_posts()


Example

get_posts() is a wrapper for a separate instance of a WP_Query object. The returned value is an array of post object.

global $post;

$args = array(
    'numberposts' => 5,
    'offset'=> 1,
    'category' => 1
);

$myposts = get_posts( $args );

foreach( $myposts as $post ) :
    setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endforeach;
wp_reset_postdata(); ?>

For more info check out the get_posts() codex page.