WordPress Latest Posts Page or Latest News Page
Creating a WordPress latest posts page or news page with excerpts (Starting Snippets of your posts) in WordPress.
We will be creating the latest posts page by using a child theme based on the default Twenty Twelve theme, if you have not yet created a child theme then read this first.
If you are not using Twenty Twelve theme then the important part is to open another page template file and copy the top of the file up to and including the the first php closing tag for the header which on this file is the get_header(); ?>,
it is important that you change the * Template Name: in the top of your file to * Template Name: Latest Posts
The first task is create a latest news page template, use the below code and copy it into a plain text editor like note pad or notepad++ which you can download from here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php /** * Template Name: Latest Posts * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ get_header(); > <div id="primary"> <div id="content" role="main"> <?php $the_query = new WP_Query( $args ); while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'page' ); ?> <!--Klick Design Added to show latest post on Latest News Page--> <div> <?php $args = array( 'numberposts' => 3 ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?> <h2>Latest Post Article <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_post_thumbnail(); the_excerpt(); ?><!--If you want to include images and full post use the_content and for thumbnails the_post_thumbnail(); see http://codex.wordpress.org/Function_Reference/the_post_thumbnail --> <?php endforeach ; ?></div><!--#entry-content--> <?php endwhile; wp_reset_postdata(); ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); > <?php get_footer(); > |
You can now save this and name it, I have named mine latest.php,
You now upload this to your child theme in /wp-content/themes/ ‘your-child-theme-name’ /page-templates, once you have done this you need to go to create the page itself.
Go to Pages>Add New in your WordPress admin area, create a new page called Latest News or Latest Posts write a small piece about the page in the content area, now on the right hand side you will see under Page Attributes>Template use the drop down and select your new template Latest Posts.
That is it you can change the number of posts shown by altering the below number from 3 to what ever you like.
1 |
$args = array( 'numberposts' => 3 ); |
Reference material for get_posts also WP_Query.
If you want to add a read more link then click here.
Hi there, I found your website via Google at the same time as looking for a related topic, your site came up, it seems to be great.
I personally question the reason why you branded this specific posting, “Latest
News Page with Excerpts | WordPress | Latest Blog Page.
Either way I loved the blog!Thanks for your time,Abby
Hi Abby, you are right I should have called it latest posts or articles? I might change it.
Thanks..
Tim
I savor, result in I discovered exactly what I was looking for. You have ended my four day long hunt! God Bless you man. Have a nice day. Bye