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:

Blog Module /

Discuss the Blog Module.

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

How to get "the latest N Blog entries except $THATID"? (RESOLVED)


Go to End


2 Posts   1558 Views

Avatar
sdbruder

Community Member, 4 Posts

19 November 2009 at 8:29am

Edited: 19/11/2009 10:37am

Im trying this:

function BlogEntries($limit=4) {
        $Blog = DataObject::get_one('BlogHolder', "Name = '".$this->blogname."'");
        if ($Blog) {
                $highlight = DataObject::get("BlogEntry",
                        "ParentID = $Blog->ID AND find_in_set('highlight',Tags)", 
                        "Date DESC", "", 1);
                if (!$highlight) {
                        return DataObject::get("BlogEntry", 
                                        "ParentID = $Blog->ID",
                                        "Date DESC", "", $limit);
                } else {
                        return DataObject::get("BlogEntry",
                                        "ParentID = $Blog->ID AND NOT ID = $highlight->ID",
                                        "Date DESC", "", $limit);
                }
        } else {
                return false; 
        }
    }

EDIT: Any way to show code using monospaced font or something similar?

But highlight->ID translates to nothing and the SQL spit it out as Couldn't run query: ....WHERE (ParentID = 1 AND NOT ID = ) AND ...

Avatar
sdbruder

Community Member, 4 Posts

19 November 2009 at 10:35am

answering my own question (actually simon_w got it on IRC), worked as

$destaque = DataObject::get_one("BlogEntry","ParentID = $Blog->ID AND find_in_set('destaque',Tags)", "Date DESC");
if ($destaque) {
    return DataObject::get("BlogEntry", 
                                        "ParentID = $Blog->ID AND NOT `SiteTree`.ID = $destaque->ID",
                                        "Date DESC", "", $limit);
} else { ....