我在Word Press上使用静态首页,我希望该页面在页面底部显示我最近的帖子。 问题是,代码仅适用于一个特定的帖子,我不知道如何告诉计算机获取最新的帖子并使其正确显示。 这是我网页的链接,请记住,它远未完成。电动汽车WordPress网站
<?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>
更改参数数组以每页选择一个帖子(使用"name"参数,您当前正在选择带有 slug "4th" 的特定帖子)。没有任何进一步的论据,应该会出现最新的帖子。
$args = 数组('posts_per_page' => 1 );
有关WordPress查询参数的更多信息,请查看Codex:https://codex.wordpress.org/Class_Reference/WP_Query 中的此页面