2012-08-28 121 views
0

我需要做什么,我的最新帖子会自动进入页面顶部?现在最新的帖子去了ealier帖子的底部。博客页面 - 显示页面顶部的最新帖子

PHP:

<div id="container"> 
    <div id="blog"> 
     <div class="grid_9 float-left"> 
      <?php foreach($posts->results as $post): ?> 
      <div class="post box_shadow"> 
       <h2><a href="<?php echo URL::to('uutiset/post/'.$post->id.'/'.\Laravel\URL::slug($post->title)) ?>"><?php echo $post->title ?></a></h2> 
       <small><?php echo date('d-m-Y',strtotime($post->date)) ?></small> 
       <p><?php echo Str::limit_word($post->content, 40); ?></p> 
       <a href="<?php echo URL::to('uutiset/post/'.$post->id.'/'.\Laravel\URL::slug($post->title)) ?>"><?php echo Lang::line('home.blog_read_more', array(), $lang)->get() ?></a> 
      </div> 
      <?php endforeach ?> 
      <?php echo $posts->links()?> 
     </div> 
    </div> 
    <div id="footer" class=" box-shadow"> 
     <?php echo stripcslashes($setting->footer)?> 
    </div> 
</div> 

我还是新手,所以你能不能给的意见,我需要修改或添加和哪里是什么线?

回答

0

这就是你的数组如何排序。选项:

`$posts->results` has all of your posts 

Replace the foreach with a for. 

$count = count($posts->results); 
for($i = $count-1; $i <= 0; $i--) { 
    $post = $posts->results[$i]; 
    //display post 
} 

最简单的,但可能不太有效的方法是foreach循环前右扭转数组:reverse the array或循环从去年开始指数将0

类似的东西下面做。

+0

我仍然是新手,所以你可以给我建议什么行我需​​要修改或添加和在哪里? – ztume

+0

当然,用例子更新了我的帖子。 – sachleen

相关问题