Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Latest News problems

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

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

Page: 1
Go to End
Author Topic: 501 Views
  • Dimenicius
    Avatar
    Community Member
    8 Posts

    Latest News problems Link to this post

    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?

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Latest News problems Link to this post

    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;
    }

  • Dimenicius
    Avatar
    Community Member
    8 Posts

    Re: Latest News problems Link to this post

    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.

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Latest News problems Link to this post

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

  • Dimenicius
    Avatar
    Community Member
    8 Posts

    Re: Latest News problems Link to this post

    i'm using v.2.4.6

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Latest News problems Link to this post

    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 %>

  • Dimenicius
    Avatar
    Community Member
    8 Posts

    Re: Latest News problems Link to this post

    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 %>

    501 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.