Wordpress在静态页面中显示最近的帖子博客

时间:2012-12-05 10:10:06

标签: php wordpress wordpress-theming

在WordPress中,我在Front page displays面板中显示一个带有Reading设置的静态首页。这很好,但我想在这个静态页面中显示最近的博客文章列表。我不确定在这个静态页面中显示最近博客文章的最佳方法是什么。那么有人可以指导我在静态页面中显示最近的博客吗?任何帮助和建议都会很明显。

2 个答案:

答案 0 :(得分:2)

尝试使用此代码来显示博客内容

<div class="blog-post-wrap">
  <?php
  $args = array( 'numberposts' => '4' );
  $recent_posts = wp_get_recent_posts( $args );
  foreach( $recent_posts as $recent ){?>
    <div class="blog"><?php echo substr($recent["post_content"], 0 , 150); ?>
      <span class="link"><?php echo '<a href="' . get_permalink($recent["ID"]) . '" title="Reaed More '.$recent["post_title"].'" >' .   'Read More'.'</a> '; ?></span>
    </blog>
  <?php } ?>
</div>

我使用<?php echo substr($recent["post_content"], 0 , 150); ?>段代码在页面上显示有限的字符。您可以根据自己的要求进行更改。

答案 1 :(得分:0)

您可以简单地使用iframe来包装您的查询,并将iframe放在任何html或php页面上,而无需触及您当前的页面代码....请参阅此链接的详细说明:http://allnigeriansinspain.com/blog/show-wordpress-post-on-static-html-page/