/** * Create looping consist archieve posts based on years format * * @todo create how function work on non-pagination mode * @param <type> $echo * @param <type> $pagination * @return mixed */ public function get_YearlyArhievesPosts($pagination = TRUE, $date_from = '', $date_to = '') { global $wpdb; /* * determine current_page to know where is our pagination page and for our main loop * @todo membuat mode meretrieve all posts, lalu berdasar per-tahun, */ $current_page = get_query_var('paged') ? get_query_var('paged') : get_query_var('page'); $current_page = !empty($current_page) && is_numeric($current_page) ? $current_page : 1; if ($pagination) { if (file_exists($pagination_path = $this->get_paginationfilepath())) { /* * determine total post to know how many pagination * the class 'pagination' will create */ if (empty($date_from)) { $date_from = $this->get_date_from(); } if (empty($date_to)) { $date_to = $this->get_date_to(); } $where = ' WHERE post_type="post" AND post_status="publish" '; $where .= $date_from . $date_to; $query = "SELECT ID, guid, post_type, post_date, post_title, post_status\n FROM {$wpdb->posts}\n {$where}"; $postresults = $wpdb->get_results($query, ARRAY_A); if (is_array($postresults)) { $total_posts = count($postresults); /** * get total pagination page that going to be created */ $posts_per_page = get_option('posts_per_page'); $max_pagination_pages = ceil($total_posts / $posts_per_page); $max_pagination_pages = $max_pagination_pages == 0 ? 1 : $max_pagination_pages; if ($total_posts > $posts_per_page) { include $pagination_path; $pagination = new Pagination(); $pagination->Items($total_posts); $pagination->limit($posts_per_page); $pagination->adjacents(1); $pagination->currentPage($current_page); $pagination->parameterName('page'); $pagination->target($this->get_target_url()); $pagination->changeClass(''); $pagination->nextLabel('DD'); $pagination->prevLabel('EE'); $pagination->nextT = '>'; $pagination->prevT = '<'; $pagination->nextI = ''; $pagination->prevI = ''; $pagination_loop = $pagination->getOutput(); $output['pagination'] = $pagination_loop; } } } } //end has_pagination state /** * get the main loop */ $output['main_loop'] = $this->get_YearlyArhieves_loop($current_page, $max_pagination_pages, $posts_per_page, $date_from, $date_to); return $output; }