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

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


Go to End


2 Posts   2054 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 { ....