WordPress: How to create ‘The Loop’ in a page?

I am creating a Specialized Page Template, where I want to display list of posts, like the blog (home page). Is it possible to create ‘The Loop’ in that page?

I think I can use get_posts() to create the loop. Is there any better method?

Related posts

Leave a Reply

2 comments

  1. Use get_posts() to query WordPress.

    <?php $all_posts = get_posts(); ?>
    

    Then instead of the while loop

    <?php while ( have_posts() ) : the_post(); ?>
    

    use the following code:

    <?php foreach ( $all_posts as $post ) : setup_postdata( $post );  ?>
    

    And it will work like The Loop.

    If anyone knows a better way, please suggest.