//load the gallery using a factory patern
$bj_gallery = BJ_Gallery::factory();
//set_ID if not in loop
//set the number of thumbnails
//set the theme thumbnail size and displays the thumbnails
$bj_gallery->set_ID(478)
->set_post_per_page(3)
->thumbnails('thumbnail');
*
*/
class BJ_Gallery {
private $ID = null,
$order = 'ASC',
$total_thumbnails,
$post_type = 'post',
$template_slug = 'gallery',
$post_per_page = 4,
$template_name;
public function set_template_name($template_name) {
$this->template_name = $template_name;
return $this;
}
public function set_template_slug($template_slug) {
$this->template_slug = $template_slug;
return $this;
}
public function set_post_per_page($post_per_page) {
$this->post_per_page = $post_per_page;
return $this;
}
public function get_post_type() {
return $this->post_type;
}
public function set_post_type($post_type) {
$this->post_type = $post_type;
}
public function set_ID($ID) {
$this->ID = $ID;
return $this;
}
public function set_order($order) {
$this->order = $order;
return $this;
}
public function set_total_thumbnails($total_thumbnails) {
$this->total_thumbnails = $total_thumbnails;
return $this;
}
public function get_total_thumbnails() {
return $this->total_thumbnails;
}
function __construct() {
//parent::__construct();
$this->set_template_slug('gallery');
}
public static function factory($template_slug = 'gallery', $post_per_page = 4) {
$factory = new BJ_Gallery();
$factory->set_template_slug($template_slug);
$factory->set_post_per_page($post_per_page);
return $factory;
}
public function gallery_thumbnails() {
global $post;
//if $ID NULL use the global post->ID
if (!isset($this->ID))
$this->ID = $post->ID;
//get the post thumbnail ID
$thumb_id = get_post_thumbnail_id($this->ID);
//image query
$images = new WP_Query(array(
'post_parent' => $this->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => $this->order,
'orderby' => 'menu_order ID',
'posts_per_page' => $this->post_per_page,
'post__not_in' => array($thumb_id),
'update_post_term_cache' => false,
));
$imagedata = $images->posts;
$this->total_thumbnails = $images->found_posts + 1;
return $imagedata;
}
public function gallery() {
global $post;
//if $ID NULL use the global post->ID
if (!isset($this->ID))
$this->ID = $post->ID;
//get the post thumbnail ID
$thumb_id = get_post_thumbnail_id($this->ID);
//image query
$images = new WP_Query(array(
'post_parent' => $this->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => $this->order,
'orderby' => 'menu_order ID',
'posts_per_page' => $this->post_per_page,
'post__not_in' => array($thumb_id),
'update_post_term_cache' => false,
));
if($images->have_posts()):
while($images->have_posts()):
$images->the_post();
bj_layout::get_template_part($this->template_slug, $this->template_name);
endwhile;
endif;
}
/**
* Display thumbnails from your gallery that links to full size image
* @param string $thumbnail_size
* @param string $class_name - css class for figure element
*/
public function thumbnails($thumbnail_size = 'gallery-tumbnail', $link = null) {
/*
* @todo make link dynamic
*/
$images = $this->gallery_thumbnails();
foreach ($images as $image) {
echo '