21282 Posts in 5730 Topics by 2601 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 260 Views |
-
Latest News problems

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?
-
Re: Latest News problems

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;
} -
Re: Latest News problems

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.
-
Re: Latest News problems

20 December 2012 at 5:10am
First question: are you using SS3+ or a previous version ?
-
Re: Latest News problems

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 %> -
Re: Latest News problems

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 %>
| 260 Views | ||
|
Page:
1
|
Go to Top |


