How to display posts on template
I've added a page template that is my new home page and I would like to be able simply list the last 5 blog entries. My home page currently looks like...
?php
/**
* This file controls the layout of your homepage
*
* @package WordPress
* @subpackage Pytheas WordPress Theme
* Template Name: Custom Home
*/
get_header(); ?
?php get_template_part('content','slider'); ?
div id="primary" class="content-area span_16 col clr clr-margin"
div id="content" class="site-content" role="main"
?php
$wp_query = new WP_Query(
array(
'post_type' = 'post',
'showposts' = of_get_option('home_blog_count','4'),
'no_found_rows' = true,
'ignore_sticky_posts' = true
)
);
if( $wp_query-posts ) { ?
div id="home-blog" class="row clr"
?php
// Display heading
if( of_get_option('home_blog_title') ) { ?
h2 class="heading"
span?php echo of_get_option('home_blog_title'); ?/span
/h2
?php } ?
div class="row clr"
?php
// Begin Loop
$wpex_count=0;
foreach( $wp_query-posts as $post ) : setup_postdata( $post );
$wpex_count++;
$wpex_clr_margin = ( $wpex_count == 1 ) ? 'clr-margin' : NULL; ?
div ?php post_class('home-blog-entry span_6 col '. $wpex_clr_margin); ?
?php
//featured image
if( has_post_thumbnail() ) { ?
a href="?php the_permalink(); ?" title="?php the_title_attribute(); ?" class="home-blog-entry-img-link"
img src="?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), wpex_img('blog_related_entry_width'), wpex_img('blog_related_entry_height'), wpex_img('blog_related_entry_crop') ); ?" alt="?php echo the_title(); ?" class="blog-entry-img" /
/a
?php } ?
h2a href="?php the_permalink(); ?" title="?php the_title_attribute(); ?"?php the_title(); ?/a/h2
div class="home-blog-entry-excerpt"
?php
// Display excerpt
echo ( !empty( $post-post_excerpt ) ) ?
apply_filters('the_content', get_the_excerpt() ) :
wp_trim_words( strip_shortcodes( get_the_excerpt() ), of_get_option('portfolio_entry_excerpt_length','200') ); ?
/div!-- /home-blog-entry-excerpt --
/div!-- /home-blog-entry --
?php
if( $wpex_count==4) {
echo 'div class="clr"/div';
$wpex_count=0;
}
endforeach; ?
/div!-- /row --
/div!-- /home-blog --
?php
}
wp_reset_postdata();?
/div!-- #content --
/div!-- #primary --
?php get_sidebar(); ?
?php get_footer();?
I'm unclear why I'm not able to do something like...
article id="post-?php the_ID(); ?" ?php post_class(); ?
div class="entry-conten clr"
?php the_content(); ?
?php wp_link_pages( array( 'before' = 'div class="page-links clr"', 'after' = '/div', 'link_before' = 'span', 'link_after' = '/span' ) ); ?
/div!-- .entry-content --
footer class="entry-footer"
?php edit_post_link( __( 'Edit Page', 'wpex' ), 'span class="edit-link"', '/span' ); ?
/footer!-- .entry-footer --
/article!-- #post --
?php comments_template(); ?
?php endwhile; ?
which is what I see on many other template files. Can someone help me understand how I can query the most recent X posts and display them using the_content();
(which I think will display the post with the author, post date, etc.)
Topic recent-posts Wordpress
Category Web