help with displaying most recent post on static page
-
Hi there
I have created a homepage template that is my static front / home page
I want to add my most recent post onto it under my static comment.
I have read numerous posts & lots of the php wordpress pages and my head is spinning …. Just when I think I understand what I am reading I realise I havn’t a clue ?? LOL
Ok so far I have 2 bits of code : – this one displays my most recent post – yay but just a link to it – how do I add the bit that actually shows the content – when I try I get errors
<?php $args = array( 'numberposts' => '1' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> '; $recent["post_content"];} ?>
This one works it displays content – BUT it shows lots of recent posts not just THE most recent 1 !!!
<?php $query = new WP_Query( array ( 'orderby' => 'date', 'order' => 'DESC' ) ); while ( $query->have_posts() ) : $query->the_post(); echo '<li>' . get_the_title() . '</li>'; ?> <div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'scrappy' ), 'after' => '</div>' ) ); ?> </div><!-- .entry-content --> <span class="media-posted-on"> <?php edit_post_link( __( 'Edit', 'scrappy' ), '<span class="media-edit-link">', '</span>' ); ?> </span> <?php endwhile; ?>
Which is my best solution & how do I get the content of my most recent posts – just the 1 ?? PLEASE – thank you
- The topic ‘help with displaying most recent post on static page’ is closed to new replies.