【问题标题】:Adding Recent post in silverstripe blog在 silverstripe 博客中添加最近的帖子
【发布时间】:2016-03-25 20:52:33
【问题描述】:

我是第一次与 silverstripe 合作,我几乎要在 silverstripe 中创建一个博客,但现在我卡在了一个需要帮助你们的地方。如果有人对此有任何想法,请帮助我。 我正在尝试在我的博客中添加最近的帖子。我为此使用以下代码

public function latestBlog($num=10) {
    /* return BlogEntry::get()->sort('PublishDate','desc')->limit($num); */
    echo $blogPosts;
    return $blogPosts = BlogPost::get()->filter('ParentID', $this->ID)->limit($num);
}

在我的 ss 页面中,我正在使用这样的 html

<% loop $latestBlog %>
    <a href="www.mydomain.com/$Title"><li>$Title</li></a>
<% end_loop %>

这给了我每篇文章的标题,但在 href 我也想要 url

如果我的标题是“TEST POST”,那么我想要像“www.mydomain.com/TEST-POST”这样的href;

任何人都可以对此有想法吗?

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    您可以使用 $Link 来返回相对 url。参考https://docs.silverstripe.org/en/3.2/developer_guides/templates/common_variables/#links

    <ul>
      <% loop $latestBlog %>
        <li><a href="$Link">$Title</a></li>
      <% end_loop %>
    </ul>
    

    【讨论】:

    • 注意:您必须在 CMS 中调整 $URLSegment 变量,它通常基于 $Title。 $Link 使用 $URLSegment...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2016-04-26
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 2020-10-06
    相关资源
    最近更新 更多