Azad chouhan
Azad chouhan

Reputation: 167

Adding Recent post in silverstripe blog

I am working with silverstripe with first time and I almost create a blog in silverstripe but now I stuck at one place where I need help you guys. If anybody have any idea about it then please help me. I am trying to add recent posts in my blog. I am using the below code for this

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);
}

And in my ss page I am using html like this

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

this gives me titles of the each post but in href I want url too

If my title is "TEST POST" then I want href like "www.mydomain.com/TEST-POST";

Can Anybody have Idea about it?

Upvotes: 0

Views: 87

Answers (1)

Gavin Bruce
Gavin Bruce

Reputation: 1809

You can use $Link which will return the relative url. Reference 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>

Upvotes: 2

Related Questions