Programmatically adding a Page Thumbnail as a Page Attribute
Permalink
I have 300+ pages on my website that I would like to programmatically add a Page Thumbnail attribute to. I already have the images I'd like to use (in the correct size as well) sitting in a local directory as a temporary measure.
What I have so far is a Pagelist that correctly identifies the pages that I'd like to add my thumbnail images to. It all falls apart when I actually try to add the specific image. The Page Thumbnail attribute is successfully added to the Page, but the image isn't included. Can anyone let me know what I've missed? Thank you!
Simplified code snippet below:
What I have so far is a Pagelist that correctly identifies the pages that I'd like to add my thumbnail images to. It all falls apart when I actually try to add the specific image. The Page Thumbnail attribute is successfully added to the Page, but the image isn't included. Can anyone let me know what I've missed? Thank you!
Simplified code snippet below:
$list = new \Concrete\Core\Page\PageList(); $list->filterByPageTypeHandle('Page'); $list->filterByParentID(1327); $pages = $list->getResults(); foreach($pages as $page) { if (file_exists(__DIR__ . 'test.png')) { $page->setAttribute('thumbnail', __DIR__ . 'test.png'); } }
Try something like this: