2
votes

I want to have a static front page on my WordPress and this static one should display the latest 5 posts and below that up to 6 custom meta fields. Thats why I changed the reading settings from last posts to "Static page", because otherwise I would not have the possibility to access the custom meta fields.

How can I now include the latest 5 blogposts on my front-page and use the default post template/output.

I did it with this query:

$latest_blog_posts = new WP_Query( array( 'posts_per_page' => 5 ) );
    if ( $latest_blog_posts->have_posts() ) : while ( $latest_blog_posts->have_posts() ) : $latest_blog_posts->the_post();
        // Loop output goes here
    endwhile; endif;

Do i now have to rewrite the code for the post here completly or can I just include the post template in some way?

Thanks!

2

2 Answers

1
votes

You need to write this line to show latest posts:

<?php 
wp_get_archives(array('type' => 'postbypost', 'limit' => 10, 'format' => 'html'));
?>

Check this link for more details

0
votes

Instead of WP_Query you should try

wp_get_recent_posts( $args, $output );

Check more details here