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

order blog by sort not by date


Go to End


5 Posts   2951 Views

Avatar
digibrains

Community Member, 130 Posts

7 October 2010 at 11:50am

/blog/code/BlogEntry.php

// By specifying a callback, you can alter the SQL, or sort on something other than date.
		if($retrieveCallback) return call_user_func($retrieveCallback, 'BlogEntry', $filter, $limit, $order);

How do you specify?

Thanks!
C.b

Avatar
carlos

Community Member, 42 Posts

7 October 2010 at 5:23pm

Hi prawnstar,

Which version of blog are you using?

This is in BlogTree class now tag 0.4.1.

What it does is calling a function that you define in order to get blog entries sorted by a different criteria.

hope it helps.

cheers

Avatar
digibrains

Community Member, 130 Posts

8 October 2010 at 4:54am

Thanks Carlos!

I was using 0.4.0, but I'm downloading 0.4.1 now.

C.b

Avatar
digibrains

Community Member, 130 Posts

8 October 2010 at 5:37am

Hi Carlos,

I downloaded 0.4.1 but still don't see a way to change this behavior without changing the function inside the /blog/code/BlogTree.php file. Is there no way to change this without hacking the script?

I'm extending the BlogHolder class. Can it be overridden there?

Thanks!
Chris.b

Avatar
carlos

Community Member, 42 Posts

8 October 2010 at 2:32pm

Edited: 08/10/2010 2:33pm

hi prawnstar,

you can do this


class MyClass extends Page {

   function MyFunc(){
     // return entries sorted by something....
   }
}

then in your code (where you want to return the entries something like this:


$blog = DataObject::get_one('BlogHolder');

$entries = $blog->Entries('','','',array('MyClass','MyFunc'),'');

In this way you can create your own function and return entries sorted by whatever you want without change the core code.

Hope it helps

cheers
Carlos