Creating a Blog Entry programmatically

Permalink
Hi,

I am using Concrete 5.7 and would like to create a blog entry programmatically.

$pagetype = PageType::getByID(6);
$pt = $pagetype->getPageTypeDefaultPageTemplateObject();
$page = $pagetype->createDraft($pt);
$pData = array('cName' => 'An automatic Blog Entry name');
$page->update($pData);


This part works ... I have problems adding Content and thumbnail.

 
goutnet replied on at Permalink Reply
The content is added into a content block, and the block is added into an area.

So you need to fetch the relevant Area and add a new Content block to it, then update the Content block actual content.

As for the thumbnail, not sure, it used to be an image block in the "Thumbnail" area, but since there is now a "thumbnail" image attribute maybe the blog entry page list template can fetch it from here. You should check the template code for more info.
goutnet replied on at Permalink Reply
Also the getByID() thing is not very robust, you should use getByHandle() instead. IDs are defined by the order of insertion into the database, whereas Handles are something that is set in stone.