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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Latest News problems


Go to End


7 Posts   1266 Views

Avatar
Dimenicius

Community Member, 8 Posts

19 December 2012 at 7:31pm

Hello,

I have to get the latest post from ALL holders and show them on the homepage.
The posts have a checkbox that defines if it will be on the news or not.

Tought it was easy, but I don't know how to get the latest 'unchecked' post from all different holders and show them on the same page.

Home
Holder 1
---Post 01 (checked)
---Post 02
Holder 2
---Post 01
---Post 02
---Post 03 (checked)

the Home page have to show the Post 02 (Holder 1) and Post 02 (holder 2) sorted by date.

Used the following code:


function ultimos() { 
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0; 
$SQL_start = (int)$_GET['start']; 
$doSet = DataObject::get("Post", "CheckboxValue = 0", "ID DESC", "", "{$SQL_start}" );
	
return $doSet ? $doSet : false; 
}

How do i get only the latest one of each holder?

Avatar
stallain

Community Member, 68 Posts

19 December 2012 at 8:38pm

Hi, I would try something like this (not tested) :

function ultimos() { 
    $holders = Holder::get();
    $uncheckedpostslist = new ArrayList();
    foreach($holders as $holdersItem) {
        $post=$holdersItem->Children()->filter('CheckboxValue','0')->Last();
        $uncheckedpostslist->push($post);
    }
    return $uncheckedpostslist;
}

Avatar
Dimenicius

Community Member, 8 Posts

20 December 2012 at 5:04am

I've changed the "$holders = Holder::get(); " to "$holders = Categoria::get(); " which is my holder page type,
then used <% control ultimos %> to show. that returned me an error:

Server error

Sorry, there was a problem with handling your request.

and all the page layout was broken. Showing only texts.

Avatar
stallain

Community Member, 68 Posts

20 December 2012 at 5:10am

First question: are you using SS3+ or a previous version ?

Avatar
Dimenicius

Community Member, 8 Posts

20 December 2012 at 6:16am

i'm using v.2.4.6

Avatar
stallain

Community Member, 68 Posts

20 December 2012 at 6:32am

OK, my code is not suitable for this version of Silverstripe.

Maybe something like this :

In Categoria.php

function ultimos() {
return DataObject::get_one('Post', "\"CheckboxValue\"=='0'",'DESC');
}

In your HomePage.php (of whatever)

function getCategoria() {
return Dataobject::get('Categoria');
}

In your home page template

<% control getCategoria %>
<% control ultimos %>
...
<% end_control %>
<% end_control %>

Avatar
Dimenicius

Community Member, 8 Posts

20 December 2012 at 7:02am

DONE! Thanks!

Have to change the "function ultimos" but everything went ok.

the final code is:

In Categoria.php

function ultimos() { 
return DataObject::get_one('Post', "CheckboxValue = 0 AND `ParentID` = '".$this->ID."'",'DESC'); 
}


In your HomePage.php (of whatever)

function getCategoria() { 
return Dataobject::get('Categoria'); 
}


In your home page template

<% control getCategoria %> 
<% control ultimos %> 
... 
<% end_control %> 
<% end_control %>