custom_query; } public function set_custom_query($custom_query) { $this->custom_query = $custom_query; } public function set_display_pagination($create_pagination) { $this->display_pagination = $create_pagination; return $this; } public function set_blank_tpl($blank_tpl) { $this->blank_tpl = $blank_tpl; return $this; } public function set_blank_tpl_name($blank_tpl_name) { $this->blank_tpl_name = $blank_tpl_name; return $this; } public function set_post_per_page($post_per_page) { $this->post_per_page = $post_per_page; return $this; } public function set_query($query) { $this->query = $query; return $this; } 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; } /** * set query for wp query * @param array $wp_query * @return \BJ_POSTDATA */ public function set_wp_query($wp_query) { $this->wp_query = $wp_query; return $this; } public function get_query() { return $this->query; } public function get_wp_query() { return $this->wp_query; } public function get_template_name() { return $this->template_name; } public function get_template_slug() { return $this->template_slug; } public function get_post_per_page() { return $this->post_per_page; } public function __construct() { } /** * * @param type $query * @param type $template_slug * @param type $template_name * @return \Post_Query */ public static function factory() { $factory = new Post_Query(); return $factory; } /** * The WP_Query object holds the WP_query object * * @return object - WP_Query object; */ public function wp_queries() { $query = new WP_Query($this->query); $this->custom_query = $query; return $query; } public function pagination($query = null) { if (!isset($query)) return; //pagination custom pagination with wp_pagenavi() if ($this->display_pagination && function_exists('wp_pagenavi')): wp_pagenavi(array('query' => $query)); //else display pagination using wordpress paginate_links() elseif ($this->display_pagination) : //set the paging methods if ($query->max_num_pages > 1) : echo '
*/
public function query($query = null) {
global $wp_query;
if (isset($query) and is_array($query))
$this->query = $query;
//set up a default query argument array();
if (!isset($this->query)) {
//get the current page ready for pagination
$this->get_current_page();
$this->query = array('posts_per_page' => 5, 'paged' => $this->current_page);
}
//if the slug is post_type use the post type name for slug instead of default content
if ($this->template_slug == 'post_type')
$this->template_slug = get_post_type();
//if the name is format will use the post format for the template name
if ($this->template_name === 'format'):
$this->template_name = get_post_format();
endif;
$this->the_posts();
}
/**
* Get post with post thumbnails (set)
* @param type $query
* @param type $template_slug
* @param type $template_name
*/
public function query_post_thumbnails($query = null, $template_slug = 'thumbnails', $template_name = '') {
$this->template_slug = $template_slug;
$this->template_name = $template_name;
if (!isset($query))
$this->query = array(
'meta_key' => '_thumbnail_id',
'posts_per_page' => $this->post_per_page,
'post_type' => 'post');
/** get the post */
$this->the_posts();
}
/**
* the post loop
*/
public function the_posts() {
$post = $this->wp_queries();
if ($post->have_posts()):
while ($post->have_posts()):
$post->the_post();
get_template_part($this->template_slug, $this->template_name);
endwhile;
endif;
/** add pagination */
$this->pagination($post);
/** now reset post fata */
wp_reset_postdata();
}
}