// ========================================================================= // SHORTCODE: Rangers Affiliates (Filtered, Paginated, Columned Layout) // ========================================================================= add_shortcode('rangers-affiliates', 'render_custom_rangers_affiliates'); function render_custom_rangers_affiliates() { global $wpdb; $table_name = 'otg_rangers_affiliates'; // 1. Get Filter and Pagination Inputs from GET parameters $filter_start_season = isset($_GET['aff_start']) ? sanitize_text_field($_GET['aff_start']) : ''; $filter_end_season = isset($_GET['aff_end']) ? sanitize_text_field($_GET['aff_end']) : ''; $filter_team = isset($_GET['aff_team']) ? sanitize_text_field($_GET['aff_team']) : ''; $filter_league = isset($_GET['aff_league']) ? sanitize_text_field($_GET['aff_league']) : ''; $paged = isset($_GET['paged']) ? max(1, intval($_GET['paged'])) : 1; $per_page = 25; $offset = ($paged - 1) * $per_page; // Season range validation logic: // If start year is after end year, reset end to start. If end is before start year, reset start/end accordingly. if (!empty($filter_start_season) && !empty($filter_end_season)) { if ($filter_start_season > $filter_end_season) { $filter_end_season = $filter_start_season; } } // Build Dynamic WHERE Clause $where_clauses = []; $params = []; if (!empty($filter_start_season)) { $where_clauses[] = "season >= %s"; $params[] = $filter_start_season; } if (!empty($filter_end_season)) { $where_clauses[] = "season <= %s"; $params[] = $filter_end_season; } if (!empty($filter_team)) { $where_clauses[] = "team_name = %s"; $params[] = $filter_team; } if (!empty($filter_league)) { $where_clauses[] = "league_name = %s"; $params[] = $filter_league; } $where_sql = ''; if (!empty($where_clauses)) { $where_sql = " WHERE " . implode(' AND ', $where_clauses); } // 2. Fetch Unique Teams and Leagues for Dropdown Filter Selects $all_teams = $wpdb->get_col("SELECT DISTINCT team_name FROM $table_name ORDER BY team_name ASC"); $all_leagues = $wpdb->get_col("SELECT DISTINCT league_name FROM $table_name ORDER BY league_name ASC"); // 3. Get Total Records Count for Pagination $count_sql = "SELECT COUNT(*) FROM $table_name" . $where_sql; if (!empty($params)) { $total_records = intval($wpdb->get_var($wpdb->prepare($count_sql, $params))); } else { $total_records = intval($wpdb->get_var($count_sql)); } $total_pages = max(1, ceil($total_records / $per_page)); if ($paged > $total_pages) { $paged = $total_pages; $offset = ($paged - 1) * $per_page; } // 4. Fetch the Paginated Dataset (Sorted by most recent season first) // Using SUBSTRING_INDEX or standard ordering depending on your season format (e.g., "2025-26" or "2025") $sql = "SELECT * FROM $table_name" . $where_sql . " ORDER BY season DESC, id DESC LIMIT %d OFFSET %d"; $query_params = array_merge($params, [$per_page, $offset]); $results = $wpdb->get_results($wpdb->prepare($sql, $query_params)); // Calculate record display range $start_record = ($total_records > 0) ? $offset + 1 : 0; $end_record = min($offset + $per_page, $total_records); $current_url = strtok($_SERVER['URI'] ?? $_SERVER['REQUEST_URI'], '?'); $query_args = $_GET; // Standardized form input style matching your site theme $input_style = 'height: 38px; padding: 0 10px; background: #161616; color: #fff; border: 1px solid #444; border-radius: 4px; box-sizing: border-box; font-size: 0.9em;'; // Start Output Wrapper $output = '
'; // Header Section $output .= '
Affiliate History
'; // Filter Form Layout $output .= '
'; // Preserve non-filter GET variables foreach ($_GET as $key => $val) { if (!in_array($key, ['aff_start', 'aff_end', 'aff_team', 'aff_league', 'paged'])) { $output .= ''; } } // Start Season Input $output .= '
'; // End Season Input $output .= '
'; // Team Filter Dropdown $output .= '
'; // League Filter Dropdown $output .= '
'; // Submit / Clear Buttons $output .= '
'; $output .= ''; $output .= 'Clear'; $output .= '
'; $output .= '
'; // Uniform Table Styles with Column Formatting to Prevent Wrapping $output .= ''; // Table structure broken down into strict, explicit columns to avoid awkward text wrapping $output .= ''; if (empty($results)) { $output .= ''; } else { foreach ($results as $row) { $image_path = $row->team_logo; if (!empty($image_path) && !preg_match('~^(?:f|ht)tps?://~i', $image_path)) { $image_path = site_url('/' . ltrim($image_path, '/')); } $logo_html = ''; if (!empty($image_path)) { $logo_html = '' . esc_attr($row->team_name) . ''; } $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; // Placeholder or extra context if needed per-row $output .= ''; } } $output .= '
Season Team Name League Affiliate Details
No affiliate history found matching your criteria.
' . esc_html($row->season) . '' . $logo_html . '' . esc_html($row->team_name) . '' . esc_html($row->league_name) . '-
'; // Pagination Footer Controls Bar $output .= '
'; $output .= '
Showing ' . $start_record . ' to ' . $end_record . ' of ' . $total_records . ' records
'; $output .= '
'; // Previous Page Button if ($paged > 1) { $prev_args = $query_args; $prev_args['paged'] = $paged - 1; $prev_url = add_query_arg($prev_args, $current_url); $output .= '« Previous'; } else { $output .= '« Previous'; } // Current Page Status Indicator $output .= 'Page ' . $paged . ' of ' . $total_pages . ''; // Next Page Button if ($paged < $total_pages) { $next_args = $query_args; $next_args['paged'] = $paged + 1; $next_url = add_query_arg($next_args, $current_url); $output .= 'Next »'; } else { $output .= 'Next »'; } $output .= '
'; $output .= '
'; // Close main wrapper return $output; } Rangerjunkiekimmie – Activity – OutsideTheGarden Boards – Page 27
JULY
«
Wed
2
Thu
3
Fri
4
Sat
5
Sun
6
Mon
7
Tue
8
»
Rangerjunkiekimmie
Rangerjunkiekimmie
Group: Registered
Joined: 2023-08-26
NHL All Star
2
Follow
Vally now says Zib lacks confidence. Rangers have too many m...

In forum Where Smit Hits The Fan

2 years ago
Panarin may get Vally fired

In forum Where Smit Hits The Fan

2 years ago
Good for Vally bad for Lavy. I hope he finally demotes playe...

In forum Where Smit Hits The Fan

2 years ago
I really think Rempe will just get better with more ice time

In forum Where Smit Hits The Fan

2 years ago
2nd PP unit gets 10 seconds

In forum Where Smit Hits The Fan

2 years ago
Thought he should've shot it. Replay looked better than live

In forum Where Smit Hits The Fan

2 years ago
Chytil, what was that?

In forum Where Smit Hits The Fan

2 years ago
1st line center drops the gloves!! That hasn't happened si...

In forum Where Smit Hits The Fan

2 years ago
I'm gonna count how many times Sam says Kreider tries to cle...

In forum Where Smit Hits The Fan

2 years ago
Kreider see's the opposition in yellow jerseys

In forum Where Smit Hits The Fan

2 years ago
Not often

In forum Where Smit Hits The Fan

2 years ago
I would say unbelievable but is it? Panarin to turnover ma...

In forum Where Smit Hits The Fan

2 years ago
Borgen after signing his contract becomes a true Ranger, giv...

In forum Where Smit Hits The Fan

2 years ago
Cuylle doing his Kreider impersonation

In forum Where Smit Hits The Fan

2 years ago
Hate how much Fox sulks...Cant stand it

In forum Where Smit Hits The Fan

2 years ago
Page 27 / 106