Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Displaying blog posts, filtered by specific category & Tag


Go to End


2 Posts   1896 Views

Avatar
Misagh

Community Member, 9 Posts

8 June 2016 at 2:04am

Hi,

I try to call recent Blog posts filtered by specific category, Through these code in my HomePage:

public function CallCategory($limit = 3) {
		return BlogPost::get()->filter(array(
		'Categories' => 'Cultural'
		))->limit($limit)->sort('LastEdited');
		}

but it doesn't work.
is there any way to call posts filtered by category?

Thanks,

Avatar
Mohammadreza

Community Member, 1 Post

11 June 2016 at 9:20pm

Edited: 11/06/2016 9:21pm

you can fix this problem with this sample code:

<% loop $Categories %>
     <a href="$Link">$Title</a>                  //(will be return the category Name

     <% loop blogPosts %>
         <a href="$Link">$Title</a>            //(will be return the all post of this category)
     <% end_loop %>

<% end_loop %>

and if you want to show this part in other pages you can use this code at the firts of your line:

<% with GetPageByType(Blog) %>


<% end_with %>