Add “Currently Playing”
-
I would like to add “Currently playing” for games that are within 95 mins of the start time when listed in the Match lists. How to do this? I am looking where is the template files but not sure where to edit.
-
This post contains an example that adds a button to each match row. You can use the same idea: add an extra parameter that checks the timestamp of the match (the match timestamp is part of the parameters that are passed to the hook) and insert that parameter as a placeholder in the template.
Thank for the suggestion. I just dont know how to do it ??
Got it done. It turns out quite simple. Thanks for the save codes & templates.
Hi @antoineh
I cant get the gmt time to substract correctly.. seems like the parameters are all in utc? so i tried to convert the server utc to gmt.. with my limited php, this is what i have so far but the minutes are -ve and not calculating properly.<?php /** * Plugin Name: Football Pool - Playing Now */ // Save this plugin in the "/wp-content/plugins" folder and activate it // class FootballPoolExtensionPlayNow { public static function init_extension() { add_filter( 'footballpool_predictionform_match_template', array( __CLASS__, 'match_row_template' ), null, 2 ); add_filter( 'footballpool_predictionform_match_template_params', array( __CLASS__, 'change_params' ), null, 4 ); } public static function change_params( $match_template_params, $match_id, $user_id, $is_user_page ) { $current_date = gmdate('M d, Y', strtotime('+ 8 hours')); $current_time = gmdate('H:i s', strtotime('+ 8 hours')); $mynote = ''; if ( $current_date == $match_template_params['match_datetime_formatted'] ) { $match_time = $match_template_params['match_time']; $diff = strtotime($current_time) - strtotime($match_time); $min_diff = $diff / 60; $hour = floor($min_diff) / 60; $min = ($min_diff % 60); if ($min < 116) { $mynote = '<span class="playing-now">Started ' .round($min,0). ' min ago</span>'; } if ($min < 1 ) { $mynote = '<span class="playing-now">Starting in '.$hour.' hr and '.$min.' min</span>'; } if ($minutes > 116 ) { $mynote = '<span class="playing-now">Completed just now</span>'; } // assume by min 116 since start, match is completed. } if ( $current_date > $match_template_params['match_datetime_formatted'] ) { $mynote = '<span class="playing-now">Completed</span>'; } $match_template_params['play_started'] = $mynote; return $match_template_params; } public static function match_row_template( $match_template, $is_user_page ) { if ( ! $is_user_page ) { if ( strpos( $match_template, '<tr>' ) !== false ) { $match_template = '<tr id="match-%match_id%-%form_id%" class="%css_class%" title="' . __('match', 'football-pool') . ' %match_id%"> <td class="time">%match_time% %play_started%</td> <td class="home">%home_team%</td> <td class="flag">%home_team_flag%</td> <td class="score">%home_input%</td> <td>-</td> <td class="score">%away_input%</td> <td class="flag">%away_team_flag%</td> <td class="away">%away_team%</td> <td>%joker%</td> <td title="' . __('score', 'football-pool') . '" class="numeric">%user_score%</td> <td>%stats_link%</td> </tr>'; } else { $match_template = '<div id="match-%match_id%-%form_id%" class="%css_class% match-card match-type-%match_type_id%" title="' . __( 'match', 'football-pool' ) . ' %match_id%"> <div class="match-card-header"> <span class="matchdate">%match_datetime_formatted%</span> <span class="time">%match_time% %play_started%</span> </div> <div class="flag">%home_team_flag%</div> <div class="flag">%away_team_flag%</div> <div class="home">%home_team%</div> <div class="away">%away_team%</div> <div class="score"> %home_input% <div class="actual-score">%home_actual_score%</div> </div> <div class="score"> %away_input% <div class="actual-score">%away_actual_score%</div> </div> <div class="match-card-footer"> <div class="user-score">%user_score_txt%</div> <div class="fp-icon">%stats_link%</div> <div class="fp-icon">%joker%</div> </div> </div>'; } } return $match_template; } } add_filter( 'plugins_loaded', array( 'FootballPoolExtensionPlayNow', 'init_extension' ) );
lol, this is solved ??
Good to see that you managed to fix it.
The dates in the database are indeed UTC because that makes it easier to use exported schedules in CSV around the world (different timezones). I use the timestamp value to compare the match date with another value (e.g. the stop time for predictions). And always in UTC. Only when I display a date, I convert it to the selected timezone, format it and localize it.
Hi Af3,
Are you willing to share your final solution?
Cause I think this is exactly what I’m looking for!Thank you in advance,
MJ@magicjohnson Hi, I am not a PHP programmer, this is just based on what I gather but so far it works for me. Its not the best code, maybe someone can help make it better. I added +8 to return the local time in my case; so you have to change this based on what is your GMT.
Btw, this is a plugin so you have to save it as a php file and put in the root of the \plugin folder and activate win wp-admin.
I also added the “locked” text in addition to the additional “Save” button. You can remove this if not needed.
Also added is a link to “Insights” for match_type > 2 — I used it in Euro 2020 for knockout rounds (match_type 2 and above) just to add a manually created page of the match to add some articles or for people to comment on. You can change the match_type, or remove the whole thing if not needed.<?php /** * Plugin Name: Football Pool - Playing Now & Extra Save Buttons * Description: Add "Playing now" for every match and Extra Save buttons, added by af3 */ // Save this plugin in the "/wp-content/plugins" folder and activate it // class FootballPoolExtensionPlayNow { public static function init_extension() { add_filter( 'footballpool_predictionform_match_template', array( __CLASS__, 'match_card_template' ), null, 2 ); add_filter( 'footballpool_predictionform_match_template_params', array( __CLASS__, 'change_parameters' ), null, 4 ); } public static function change_parameters( $match_template_params, $match_id, $user_id, $is_user_page ) { // 1. First we add Playing Now Params $mynote = ''; $current_date = gmdate('M d, Y', strtotime('+ 8 hours')); $current_timestamp = gmdate('M d, Y H:i:s', strtotime('+ 8 hours')); $game_date = $match_template_params['match_datetime_formatted'].' '.$match_template_params['match_time']; $duration = strtotime($game_date) - strtotime($current_timestamp); $min = $duration / 60; $hours = floor(abs($min) / 60); $minutes = (abs($min) % 60); if ( $current_date == $match_template_params['match_datetime_formatted'] ) { if ($min > 1 && $min < 116 ) { $mynote = '<span class="playing-now">Starting in ' .round($min,0). ' mins</span>'; } elseif ($min > 116 ) { $mynote = '<span class="playing-now">Playing in ' .$hours.' hrs, '. $minutes. ' mins</span>'; } elseif ($min < -116 ) { $mynote = '<span class="playing-now">Played '.round(abs($min),0).' mins ago</span>'; } elseif ($min > -166 && $min < 1 ) { $mynote = '<span class="playing-now">Started '.round(abs($min),0).' mins ago</span>'; } } elseif ( strtotime($current_date) < strtotime($match_template_params['match_datetime_formatted']) ) { if ($min < 240 ) { $mynote = '<span class="playing-now">Playing in '. round(abs($min),0). ' mins</span>'; } else { $mynote = '<span class="playing-now">Coming up</span>'; } } elseif ( strtotime($current_date) > strtotime($match_template_params['match_datetime_formatted']) ) { $mynote = '<span class="playing-now">Completed</span>'; } if ($match_template_params['match_type_id'] > 2) { $match_template_params['home_team']= str_replace(' ', '-', $match_template_params['home_team']); $match_template_params['away_team']= str_replace(' ', '-', $match_template_params['away_team']); $mynote .= '<span class="match_info"><a href="'.home_url( '/' ).strtolower($match_template_params['home_team']).'-vs-'.strtolower($match_template_params['away_team']).'">Insights</a></span>'; } $match_template_params['play_started'] = $mynote; // 3. Now we add extra save buttons if ( $match_template_params['match_is_editable'] == true ) { $match_template_params['save_button'] = '<input type="submit" value="save" /><span class="closing-time">Locked 15mins before match</span>'; } else { $match_template_params['save_button'] = ''; } // 4. FInally, send all the new params for the template return $match_template_params; } public static function match_card_template( $match_template, $is_user_page ) { if ( ! $is_user_page ) { if ( strpos( $match_template, '<tr>' ) !== false ) { $match_template = '<tr id="match-%match_id%-%form_id%" class="%css_class%" title="' . __('match', 'football-pool') . ' %match_id%"> <td class="time">%match_time% %play_started%</td> <td class="home">%home_team%</td> <td class="flag">%home_team_flag%</td> <td class="score">%home_input%</td> <td>-</td> <td class="score">%away_input%</td> <td class="flag">%away_team_flag%</td> <td class="away">%away_team%</td> <td>%joker%</td> <td title="' . __('score', 'football-pool') . '" class="numeric">%user_score%</td> <td>%stats_link% %save_button%</td> </tr>'; } else { $match_template = '<div id="match-%match_id%-%form_id%" class="%css_class% match-card match-type-%match_type_id%" title="' . __( 'match', 'football-pool' ) . ' %match_id%"> <div class="match-card-header"> <span class="matchdate">%match_datetime_formatted%</span> <span class="time">%match_time% %play_started%</span> </div> <div class="flag">%home_team_flag%</div> <div class="flag">%away_team_flag%</div> <div class="home">%home_team%</div> <div class="away">%away_team%</div> <div class="score"> %home_input% <div class="actual-score">%home_actual_score%</div> </div> <div class="score"> %away_input% <div class="actual-score">%away_actual_score%</div> </div> <div class="match-card-footer"> <div class="user-score">%user_score_txt%</div> <div class="fp-icon">%stats_link%</div> <div class="fp-icon">%joker%</div> </div> <div class="match-card-save">%save_button%</div> </div>'; } } return $match_template; } } add_filter( 'plugins_loaded', array( 'FootballPoolExtensionPlayNow', 'init_extension' ) );
Hi af3,
Thanks a lot for sharing!
Highly appreciated!MJ.
- The topic ‘Add “Currently Playing”’ is closed to new replies.