简体   繁体   中英

Trying to add recent post to static front page in Wordpress

I am using a static front page on Word Press, and I want the page to show my most recent post on the bottom of the page. The problem is, the code is only for one particular post, and I don't know how to tell the computer to get the most recent post and to make it show up correctly. Here's a link to my webpage, keep in mind it's nowhere near complete. Electric Car WordPress Site

<?php 
                $args = array('name' => '4th');
                $query = new WP_Query( $args );
                while ( $query->have_posts() ) : $query->the_post(); ?>


            <div class="post">

                <!-- Display the Title as a link to the Post's permalink. -->

                <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

                <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->

                <small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>

                <!-- Display the Post's content in a div box. -->

<div class="entry">
    <?php the_content(); ?>


    <?php // get_template_part( 'content', 'single' ); ?>


</div>

Change your arguments array to select one post per page (using the "name" parameter you are currently selecting a specific post with the slug "4th"). Without any further arguments, the most recent post should appear.

$args = array('posts_per_page' => 1 );

For more on WordPress query parameters, check out this page in the Codex: https://codex.wordpress.org/Class_Reference/WP_Query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM