douzhang7603 2017-04-24 17:17
浏览 23

如何在silverstripe首页上显示最近的新闻

I am using the silverstripe/simple_news module from Arno Poot for my SilverStripe 3.5.3 CMS.

The news module works perfectly and news is saved and displayed normally. I am just not happy with the way it displays on the page.

I would like to put a news brief div on the front page with the last 10 news articles. But I have little documentation to go by. How would I get the last 10 news articles.

I also would like to create a sidebar on the news holder page listing the entire news archive in order / group links by:

--------------- 
| Year        |      Page Content listing of this month only  
|   Month     | 
|     Date    |  
| Year        | 
|  Month      |  
|    Date     | 
--------------

...etc. (pub date as dd-MM-yyyy)

I think the operation should be similar but since I am somewhat new at customizing SilverStripe, I have many questions yet.

  • 写回答

1条回答 默认 最新

  • duanban4769 2017-04-24 21:16
    关注

    Great question. Syndication of content is a really fundamental pattern in SilverStripe development, or really any content management system. A guiding principle of SilverStripe is that it would much rather empower you create exactly what you want by writing some code than give you 80% of what you want in some turnkey, out-of-the-box solution.

    There's a lot written about this already. See https://docs.silverstripe.org/en/3/tutorials/extending_a_basic_site/#showing-the-latest-news-on-the-homepage.

    What you'll want to do is create a method in your home page controller that returns a list of articles to your home page template.

    public function RecentNews()
    {
      return NewsArticle::get()->limit(5); // sort is already handled by default_sort
    }
    

    Then on the template:

    <% loop $RecentNews %>
    $Title / $Date / etc..
    <% end_loop %>
    

    Your second question about grouping them by year is a bit trickier. I did a tutorial on this a while back. Check out https://www.silverstripe.org/learn/lessons/beyond-the-orm-building-custom-sql?ref=hub

    Needless to say, update all of those class names and field names to reflect the module you're using, e.g. ArticlePage -> NewsPage.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100