'; $posts_data_json_str = file_get_contents('posts/posts.json'); //add to cache Mox_Cache::store('restive_blog_post_data', $posts_data_json_str); } else { //echo 'cached
'; $posts_data_json_str = $posts_data_json_cache_str; } **/ $posts_data_json_str = file_get_contents('posts/posts.json'); //Get Post Authors /** $posts_data_authors_json_cache_str = Mox_Cache::fetch('restive_blog_post_author_data'); if(!$posts_data_authors_json_cache_str) { $posts_data_authors_json_str = file_get_contents('posts/authors.json'); Mox_Cache::store('restive_blog_post_author_data', $posts_data_authors_json_str); } else { $posts_data_authors_json_str = $posts_data_authors_json_cache_str; } **/ $posts_data_authors_json_str = file_get_contents('posts/authors.json'); $post_data_json_arr = json_decode($posts_data_json_str, true); $post_author_data_json_arr = json_decode($posts_data_authors_json_str, true); $posts_arr = $post_data_json_arr['posts']; $posts_final_arr = $post_data_json_arr['posts']; //reverse array to put it in chronological order $posts_arr = array_reverse($posts_arr); $posts_final_arr = array_reverse($posts_final_arr); $show_breadcrumb_bool = false; //Filter posts $tag_is_active_bool = false; $category_is_active_bool = false; if(!empty($tag_name_str)) { //1: By tag $tag_is_active_bool = true; $show_breadcrumb_bool = true; $html_breadcrumb_text_leader_str = 'Tag'; $html_breadcrumb_text_value_str = ucfirst($tag_name_str); $tag_item_arr = array(); $posts_final_arr = array(); for($i = 0; $i < count($posts_arr); $i++) { $tag_item_arr = explode(',', $posts_arr[$i]['tags']); $tag_item_arr = array_map('trim', $tag_item_arr); if(in_array($tag_name_str, $tag_item_arr)) { $posts_final_arr[] = $posts_arr[$i]; } } } else if(!empty($category_name_str)) { //2: By Category $category_is_active_bool = true; $show_breadcrumb_bool = true; $html_breadcrumb_text_leader_str = 'Category'; $html_breadcrumb_text_value_str = ucfirst($category_name_str); $tag_item_arr = array(); $posts_final_arr = array(); for($i = 0; $i < count($posts_arr); $i++) { $category_item_arr = explode(',', $posts_arr[$i]['category']); $category_item_arr = array_map('trim', $category_item_arr); if(in_array($category_name_str, $category_item_arr)) { $posts_final_arr[] = $posts_arr[$i]; } } } //manage pagination $page_item_limit_int = 10; $page_num_int = (isset($_GET['page']) && !empty($_GET['page'])) ? intval($_GET['page']) : 1; $page_num_next_int = $page_num_int + 1; $page_num_prev_int = $page_num_int - 1; $page_item_end_int = $page_num_int * $page_item_limit_int; $page_item_start_int = $page_item_end_int - ($page_item_limit_int - 1); $page_chunk_num_int = $page_num_int - 1; $posts_final_chunk_arr = array_chunk($posts_final_arr, $page_item_limit_int); $posts_final_chunk_size_int = count($posts_final_chunk_arr); $posts_final_arr = $posts_final_chunk_arr[$page_chunk_num_int]; $show_page_nav_bool = false; $show_page_nav_older_bool = false; $show_page_nav_newer_bool = false; if(!empty($posts_final_chunk_arr[$page_chunk_num_int])) { $show_page_nav_bool = true; $show_page_nav_older_bool = true; if($page_num_int <= $posts_final_chunk_size_int && $page_num_int > 1) { $show_page_nav_newer_bool = true; } if ($page_num_int >= $posts_final_chunk_size_int) { $show_page_nav_older_bool = false; } if($tag_is_active_bool) { $page_nav_url_older_str = Mox_Url::getURL('1', '1', '0').'/posts/tag/'.$tag_name_slug_str.'/page/'.$page_num_next_int; $page_nav_url_newer_str = Mox_Url::getURL('1', '1', '0').'/posts/tag/'.$tag_name_slug_str.'/page/'.$page_num_prev_int; } else if ($category_is_active_bool) { $page_nav_url_older_str = Mox_Url::getURL('1', '1', '0').'/posts/category/'.$category_name_slug_str.'/page/'.$page_num_next_int; $page_nav_url_newer_str = Mox_Url::getURL('1', '1', '0').'/posts/category/'.$category_name_slug_str.'/page/'.$page_num_prev_int; } else { $page_nav_url_older_str = Mox_Url::getURL('1', '1', '0').'/page/'.$page_num_next_int; $page_nav_url_newer_str = Mox_Url::getURL('1', '1', '0').'/page/'.$page_num_prev_int; } } ?> Restive Blog