I need to customize the player & events template
-
I need to customize the player & events template page to fit my design
-
Hi @sharko,
We’re putting some documentation together, including a theme integration guide that will help you create your own page templates. I’ll let you know when the documentation becomes available.
In the meantime, let me know if you have any specific questions that I can answer ??
I was wondering the same.
Is “content-single-event.php” the .php template used for events? I tried to edit it, but it doesn’t seems to affect the Event pages at all.
Hi @alaaaaa,
The content-single-event.php template file is part of the template system. It is used for events, but there are other files that hook into it.
In includes/sp-template-hooks.php, you’ll find the following lines:
add_action( 'sportspress_single_event_content', 'sportspress_output_event_video', 10 ); add_action( 'sportspress_single_event_content', 'sportspress_output_event_results', 20 ); add_action( 'sportspress_single_event_content', 'sportspress_output_event_details', 30 ); add_action( 'sportspress_single_event_content', 'sportspress_output_event_venue', 40 ); add_action( 'sportspress_single_event_content', 'sportspress_output_event_performance', 50 );
You don’t need to edit these lines, though. Instead, you can remove each action (if needed) or add your own actions to ‘sportspress_single_event_content’. Here is an example of each:
Remove the venue output
remove_action( 'sportspress_single_event_content', 'sportspress_output_event_venue', 40 );
Add a new section to events
add_action( 'sportspress_single_event_content', 'my_event_output_function', 40 );
(be sure to define ‘my_event_output_function’ in this case)
The other option is to create your own page template. You can do this by making a copy of single.php in your theme folder, and adding it to a new folder called ‘sportspress’. The files should be single-(post_type).php. For example, the path to an event template that would override the default event page is:
your_theme/sportspress/single-event.php
We’ll be launching the documentation portal very soon, which will outline all of this in more detail ??
Thank you very much for the hints, really interesting.
One more question, is there any easy code snippet for displaying data such as: team A name, team B name, event name, countdown and basically all the rest of “single” elements which are used within the shortcodes?
Currently I’m using for example:
$leagues = get_the_terms( $post->ID, 'sp_league' ); if ( $leagues ): foreach( $leagues as $league ): $term = get_term( $league->term_id, 'sp_league' ); ?> <h5 class="event-league">event: <?php echo $term->name; ?></h5> <?php endforeach; endif;
for displaying the league name and
$leagues = get_the_terms( $post->ID, 'sp_league' ); if ( $leagues ): foreach( $leagues as $league ): $term = get_term( $league->term_id, 'sp_league' ); ?> <h5 class="event-league">teams: <?php echo $term->name; ?></h5> <?php endforeach; endif;
+ some data scraping for displaying “single” team names (in order to display just “TEAM A” instead of “TEAM A vs TEAM B”), since I want to link them to their corresponding team page.
Is there any better way for retrieve this kind of data within the template page?
thank you again.
Hi again!
Great point. We’ll look into adding code snippets to get elements for use in templates.
For now, there are a couple of helper functions that you can use.
First, get the ID. Inside the loop, you can use:
$id = get_the_ID();
Or if you have the event as a post object, use:
$id = $post->ID;
Get team names as array (do this before displaying team names):
$teams = get_post_meta( $id, 'sp_team' );
Display first team name:
echo get_the_title( $teams[0] );
Display second team name:
echo get_the_title( $teams[1] );
Display event name:
the_title();
Display countdown:
sp_get_template( 'countdown.php', array( 'id' => $id ) );
Display event details:
sp_get_template( 'event-details.php', array( 'id' => $id ) );
Display event performance:
sp_get_template( 'event-performance.php', array( 'id' => $id ) );
Display event results:
sp_get_template( 'event-results.php', array( 'id' => $id ) );
Hope this helps ??
How do I build a player page with this, it all looks like team and league code?
If I am not able to do a custom player page is there a way to add CSS to make it look more like my theme?
Thank you for your hep so far.
@james there are also player-related templates in the /templates folder. If you’d like to add some CSS, you can do so via SportsPress > Settings > Custom CSS.
All SportsPress tables have the class “sp-data-table” and there are specific classes for each type, for example “sp-league-table”, “sp-player-performance”, etc.
Hi,
I’m working on my own template of event-results.php. And I was wondering how do I get to display the result of the match? I have this:
$id = get_the_ID(); $teams = get_post_meta( $id, 'sp_team' ); $result = get_post_meta( $id, 'sp_results' ); echo '<div id="box-event"> <table> <tr> <td class="team-1">' . get_the_title( $teams[0] ) . '</td> <td class="result">' . $result . '</td> <td class="team-2">' . get_the_title( $teams[1] ) . '</td> </tr> </table> </div> <br>';
Where there is $result, there should be the score of the match.
Thx for your time and help.
grtzHi Symphasia!
I would like to begin with that I am far from good with php, so I leave no warranty on what I am about to give you here. But, it will print the score. ?? If someone out there (and I’m sure there is!) knows a better way to do it, please do!
$id = $post->ID; $teams = get_post_meta( $id, 'sp_team' );/*Array of teams data*/ $results = get_post_meta( $id, 'sp_results' );/*Array of result data*/ $home = $results['0'][$teams[0]]['goals'];/*Drills down in the array to get the value of goals for the home team*/ $away = $results['0'][$teams[1]]['goals'];/*Drills down in the array to get the value of goals for the away team*/ /* Show Score*/ print("<h3>".$home.' - '.$away. "</h3>"); /* End Show Score*/
@knut23 Thanks for chiming in! That method will definitely work. We recently added an API function to make it easier:
sp_the_main_results( $id );
An optional parameter can be added as a delimiter, for example if you prefer to display the score as 1 : 2 instead of 1 – 2:
sp_the_main_results( $id, ‘:’ );
Hope this helps!
Thanks for chiming in!
You’re welcome, I try my best to give something back!
We recently added an API function to make it easier
:
If I just knew that before! ?? Since my php abilities are very undeveloped I spent maaany hours trying to get my solution to work! On the other hand I did learn quite a bit during my research. ?? So it was not all wasted.Do you perhaps have more “secret” functions you can share? Or a list of them on some page somewhere?
And then it struck me: They all live in sp-api-functions.php in the includes folder, don’t they!?
/Richard
Good Morning and let me first say, that l love your plugin, its amazing, the question l have is that l need to make tables with specific data, especially ranking top 100 player, we are a sports combine site, here is the link to Cal State Game
Rank Name Pos Location Stars Ht Wt School
#1 Byron Cowart DE Seffner, FL 5 stars 6’3″ 252 listI hope all this makes sense, we rank players Top 100 players in specific categories
@knut23 Yep, we added sportspress/includes/sp-api-functions.php in version 1.4 and will be adding more functions in the next major update ??
@visaliaweb Glad to hear you’re enjoying the plugin! I’m happy to help you set up the top player lists on your site. The best way to do this is to create a Player List (Players & Staff > Player Lists) for each category, then select an “Orderby” column in the settings for that player list.
You can also create additional statistics and metrics via SportsPress > Configure, and change the number of rows to display via SportsPress > Settings > Players.
Feel free to let me know if you have any specific questions about player lists ??
Good morning everyone. First of all, this plugin is amazing and my question is regarding the countdown page. I edited the file, but it’s not showing the venue. Can someone look at the code and see what I’m doing wrong? Thank you.
———————-
if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly
$defaults = array(
‘team’ => null,
‘id’ => null,
‘live’ => get_option( ‘sportspress_enable_live_countdowns’, ‘yes’ ) == ‘yes’ ? true : false,
);if ( isset( $id ) ):
$post = get_post( $id );
else:
$args = array();
if ( isset( $team ) )
$args = array( array( ‘key’ => ‘sp_team’, ‘value’ => $team ) );
$post = sp_get_next_event( $args );
endif;extract( $defaults, EXTR_SKIP );
if ( ! isset( $post ) ) return;
$id = $post->ID;
$teams = get_post_meta( $id, ‘sp_team’ );?>
<div class=”upcoming-match-item-wrapper gdlr-item” style=”margin-bottom: 0px;”>
<div class=”upcoming-match-overlay”></div>
<div class=”gdlr-upcoming-match-team-wrapper”>
<span class=”gdlr-upcoming-match-team gdlr-left”><?php echo get_the_title( $teams[0] ); ?></span>
<span class=”gdlr-upcoming-match-versus”>VS</span>
<span class=”gdlr-upcoming-match-team gdlr-right”><?php echo get_the_title( $teams[1] ); ?></span>
</div>
<span class=”match-result-info-wrapper”>
<span class=”upcoming-match-info-overlay”></span>
<span class=”match-result-info”>
<i class=”icon-location-arrow”></i>
<?php
if ( isset( $show_venue ) && $show_venue ):
$venues = get_the_terms( $post->ID, ‘sp_venue’ );
if ( $venues ):
echo the_terms( $post->ID, ‘sp_venue’ );
endif;
endif;if ( isset( $show_league ) && $show_league ):
$leagues = get_the_terms( $post->ID, ‘sp_league’ );
if ( $leagues ):
foreach( $leagues as $league ):
$term = get_term( $league->term_id, ‘sp_league’ );
echo $term->name;
endforeach;
endif;
endif; ?>
</span>
<span class=”match-result-info”>
<i class=”icon-calendar”></i><?php $now = new DateTime( current_time( ‘mysql’, 0 ) ); $date = new DateTime( $post->post_date );
$interval = date_diff( $now, $date );$days = $interval->invert ? 0 : $interval->days;
$h = $interval->invert ? 0 : $interval->h;
$i = $interval->invert ? 0 : $interval->i;
$s = $interval->invert ? 0 : $interval->s;
?><time datetime=”<?php echo $post->post_date; ?>”<?php if ( $live ): ?> data-countdown=”<?php echo str_replace( ‘-‘, ‘/’, $post->post_date ); ?>”<?php endif; ?>><?php echo sprintf( ‘%02s’, $days ); ?> <small><?php _e( ‘days’, ‘sportspress’ ); ?></small><?php echo sprintf( ‘%02s’, $h ); ?> <small><?php _e( ‘hrs’, ‘sportspress’ ); ?></small><?php echo sprintf( ‘%02s’, $i ); ?> <small><?php _e( ‘mins’, ‘sportspress’ ); ?></small><?php echo sprintf( ‘%02s’, $s ); ?> <small><?php _e( ‘secs’, ‘sportspress’ ); ?></small></time></span>
</span>
</div>
- The topic ‘I need to customize the player & events template’ is closed to new replies.