2016-04-28 32 views
1

我在Word Press上使用了一个静态的页面,并且我希望页面能够在页面底部显示我最近的帖子。问题是,代码仅适用于某个特定的帖子,我不知道如何告诉计算机获取最新帖子并使其正确显示。这里有一个链接到我的网页,请记住它远没有完成。 Electric Car WordPress Site试图添加最近的帖子到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> 
+0

在你的$ args - 删除名称= ....作为特别要求这个职位。你可能想在那里添加你自己的参数来确切地指定你想要的。查看http://codex.wordpress.org/Function_Reference/WP_Query获取更多信息 –

+0

https://codex.wordpress.org/Function_Reference/wp_get_recent_posts 非常简单,只需删除您不需要的任何参数即可。 –

回答

0

更改参数数组来选择每页一个后(使用“名称”参数,您正在选择一个特定的职位与弹头“五·四”)。没有任何进一步的论据,最近的帖子应该出现。

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

更多关于WordPress的查询参数,看看这个页面法典:https://codex.wordpress.org/Class_Reference/WP_Query

+0

谢谢,现在它只显示我最近的帖子。想知道如何让它看起来像一个普通的帖子吗?现在它只是显示在屏幕上的超链接文本。 –

+0

“普通帖子”是什么意思?您可以编码以显示您想要的任何内容:精选图片,帖子标题,帖子摘录,完整内容等。这取决于您想要的内容。上面粘贴的代码是要求帖子标题(作为帖子的超链接),帖子日期和作者以及内容......模板部分注释掉了(所以它不会出现)。 – alabele

+0

好的,谢谢,我终于明白了。 –

相关问题