Skip to content

Instantly share code, notes, and snippets.

@atticoos
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save atticoos/9d47360727a3b02be192 to your computer and use it in GitHub Desktop.

Select an option

Save atticoos/9d47360727a3b02be192 to your computer and use it in GitHub Desktop.
<?php
class WP_PageModel {
function __construct ($postID = false) {
global $post;
$this->postID = $postID ? $postID : $post->ID;
}
protected function fillModelAttributes(&$attribute, $data) {
$attribute = new stdClass();
foreach ($data as $key=>$value) {
$attribute->$key = $data;
}
}
}
class HomePageModel extends WP_PageModel {
var $top;
var $features;
var $bottom;
function __construct ($postID = false) {
parent::__construct($postID);
$this->fetchTop();
$this->fetchFeatures();
$this->fetchBottom();
}
function fetchTop () {
$image = get_field('top_background_image');
$image = !empty($image) ? $image : get_field('default_banner_image', 'option');
$topModel = array (
'image' => $image,
'heading' => get_field('top_title', $this->postID),
'excerpt' => get_field('top_excerpt', $this->postID))
);
$this->fillModelAttributes($this->top, $topModel);
}
function fetchFeaturedItems () {
$this->fillModelAttributes($this->featuredItems, array(
'items' => get_field('featured_items', $this->postID);
));
}
function fetchBottom () {
$bottomModel = array (
'heading' => get_field('heading_bottom', $this->postID),
'excerpt' => get_field('excerpt_bottom', $this->postID)
);
$this->fillModelAttributes($this->bottom, $bottomModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment