Get blog posts in homepage

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version:

Question:

hello sir i am using blog module for blog posts. my question is :- “how can i get all blog post(only blog post) in descending order in home page .” My controller for HomePage :- HomePage_Controller.php home page template :- HomePage.ss i want get

hello sir
i am using blog module for blog posts.
my question is :-
“how can i get all blog post(only blog post) in descending order in home page .”

My controller for HomePage :- HomePage_Controller.php
home page template :- HomePage.ss

i want get blog in homepage.

can you help me please.
plz give me full code .

thanks in advance
hello sir
i am using blog module for blog posts.
my question is :-
“how can i get all blog post(only blog post) in descending order in home page .”

My controller for HomePage :- HomePage_Controller.php
home page template :- HomePage.ss

i want get blog in homepage.

can you help me please.
plz give me full code .

thanks in advance

// Include any relevant code. If you have a lot of code, link to a gist instead.

In your HomePage class, you should be able to add a simple method, such as:

public function getAllBlogPosts() {
  return BlogPost::get();
}

And then in your template, you’d just loop over the result of that with whatever markup you need:

<% loop $AllBlogPosts %>
  <article>
   <h2>$Title</h2>
  </article>
<% end_loop %>
1 Like

when i use this i have a error :-

[Emergency] Uncaught Error: Class ‘BlogPost’ not found

You will probably need to add the right use statement at the top of your HomePage class to make sure that PHP understands where to find the BlogPost class:

use SilverStripe\Blog\Model\BlogPost;

1 Like

Use Phpstorm as editor and Phpstorm will add it automatically to the top.

Thank you soo much …

1 Like

Thanku soo much . it worked