Viewing 12 replies - 1 through 12 (of 12 total)
  • I would also like to second IStephen comments on how to customize player profile pages. There seems to be no documentation on how to re-arrange the data that is displayed on a player profile page.

    I’d like to display the stats in a different order, for example, I have stats for their season games and stats for their playoffs games. Currently it just displays the stats based on alphabetical order, so because “P” for playoffs comes before “S” for season, it displays the playoffs first before Season, but I would like to flip these around.

    Its nice that you can choose which seasons are displayed by clicking them on each player admin section. But it would be also good if you can display the total line of all the stats for all seasons. There is no click option there.

    Another change for displaying the stats, is that it would be nice to separate the batting stats from the pitching stats. Currently they are all displayed in the same table, making the table really wide and you have to scroll right alot to view all the stats. Can there be a way to display the batting and pitching stats on separate lines or separate tables for each season if they are a pitcher.

    I’d also like to change how the player details are displayed beside the photo of the player. Currently they are just pulled from the database and displayed in a list, which is way too long and I cant choose which one I want to display and which one I dont. It would be nice to customize the page template and choose how I want the data to be displayed.

    I did try to make changes to the player_details.php page, however, when I updated the sportpress to the latest version, the file was overwritten back to the default.

    Here is an example of my player profile website – http://teambradysbunch.com/archives/player/john-sorbera

    I have submitted various other forum postings regarding these issues with the player profile pages, but no one from the plugin moderator has replied to any of them.

    I really like this plugin and I have been supporting it, but I would like to make the pages work better but I just need some guidance and help to do so.

    Thanks
    Chris

    Thread Starter lstephan

    (@lstephan)

    Hi Chris

    We have the same difficulties to customize our details pages designs.
    In fact, it would be great if Sportspress details pages would be created by table design for example and not pure php coding. That would let the possibility of everyone to customize details pages.

    Otherwise it’s a great extension that could be wonderful with customizing details pages πŸ˜‰

    Thanks
    Lstephan

    I’ve been trying to understand how to customize the template pages based on the limited documentation provided on the sportspress developer page.

    It would be great if you could post an example, php code of a custom template page for a single-player.php. I’m trying to figure out what coding I need to use to echo a single metric of a player (ie: height) from the database, or the code to echo the profile category (ie: biography) of the player.

    I’ve figured out that it needs to be in the loop to go through the data, but how do I pull the particular item out of it? Any examples would be appreciated.

    Thread Starter lstephan

    (@lstephan)

    Hi

    I began to customize some page but i have to code directly in php when i m not so familiar with it but rather with aspx.

    So i modified team-details.php page like this to modify the way datas are displayed ( but i have to modify the right css style but difficult to find the right style and where to modify it).

    An example of the piece of code to modify :

    $output .= ‘<table width=”50%” border=”2″ align=”right”>
    <tr><td bgcolor=”#99FF00″>’ . $label .”:::”.'</td><td>’ . $value . ‘</td>’.’ </tr>
    </table>’;

    Regards

    So I managed to figure out how to display the profile category from the player.

    I went ahead and created a single-player.php template and I added the following code:

    if ( ! isset( $id ) )
    $id = get_the_ID();

    $content = ‘<div class=”sp-post-content”>’ . get_post_field(‘post_content’, $id) . ‘

    </div>’;

    echo do_shortcode($content);

    I ran the do_shortcode function on the content cause i have a shortcode in the biography. This way it displayed it correctly.

    Not sure if this is the correct way to do it, but it seems to work.

    I still need to figure out how to just show one specific metric from all the data. I see that you modified the the $output to a table instead of a list. But you said that you made the changes in the team-details.php. By doing that, when the next update comes, your changes will be over written. Maybe you should try creating a template file, single-team.php and adding your code there.

    Thread Starter lstephan

    (@lstephan)

    Hi Chris,

    You re right when the next uptade will come i have to rewritte it. So i will try to make changes like you.

    Could u post your single-player.php template ?

    So i could have a look on it.

    Regards

    Here is the single-player file coding that I used. Once I copied the page.php file into the sportspress folder on the theme folder, I did trial and error of replacing the_content(); line with php coding from the individual player files (player-metrics.php, player-statistics.php, etc..) found in the template folders for the plugin.

    <?php
    /**
     * Template File - Single-player.
     */
    ?>
    
    <?php get_header(); ?>
    
    	<?php do_action( 'spacious_before_body_content' ); ?>
    
    	<div id="primary">
    		<div id="content" class="clearfix">
    			<?php while ( have_posts() ) : the_post(); ?>
    
    <?php
    /**
     * This is the start of the main content section.
     */
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<?php do_action( 'spacious_before_post_content' ); ?>
    	<div class="entry-content clearfix">
    
    <?php
    /**
     * Player Photo - taken from player-photo file.
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    if ( get_option( 'sportspress_player_show_photo', 'yes' ) === 'no' ) return;
    
    if ( ! isset( $id ) )
    	$id = get_the_ID();
    
    if ( has_post_thumbnail( $id ) ):
    	?>
    	<div class="sp-template sp-template-player-photo sp-template-photo sp-player-photo">
    		<?php echo get_the_post_thumbnail( $id, "medium" ); ?>
    	</div>
    	<?php
    endif;
    
    /**
     * Player Metrics - taken from player details file.
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    if ( get_option( 'sportspress_player_show_details', 'yes' ) === 'no' ) return;
    
    if ( ! isset( $id ) )
    	$id = get_the_ID();
    
    $defaults = array(
    	'show_nationality_flags' => get_option( 'sportspress_player_show_flags', 'yes' ) == 'yes' ? true : false,
    	'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
    );
    
    extract( $defaults, EXTR_SKIP );
    
    $countries = SP()->countries->countries;
    
    $player = new SP_Player( $id );
    
    $nationality = $player->nationality;
    $positions = $player->positions();
    $current_teams = $player->current_teams();
    $past_teams = $player->past_teams();
    $metrics_before = $player->metrics( true );
    $metrics_after = $player->metrics( false );
    
    $common = array();
    if ( $nationality ):
    	if ( 2 == strlen( $nationality ) ):
    		$legacy = SP()->countries->legacy;
    		$nationality = strtolower( $nationality );
    		$nationality = sp_array_value( $legacy, $nationality, null );
    	endif;
    	$country_name = sp_array_value( $countries, $nationality, null );
    	$common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : 'β€”';
    endif;
    
    // I comment out this section because I didn't want the position default metric to be displayed.  I created another position metric for the player.
    //if ( $positions ):
    	//$position_names = array();
    	//foreach ( $positions as $position ):
    	//	$position_names[] = $position->name;
    	//endforeach;
    	//$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
    //endif;
    
    $data = array_merge( $metrics_before, $common, $metrics_after );
    
    if ( $current_teams ):
    	$teams = array();
    	foreach ( $current_teams as $team ):
    		$team_name = get_the_title( $team );
    		if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
    		$teams[] = $team_name;
    	endforeach;
    	$label = _n( 'Current Team', 'Current Teams', count( $teams ), 'sportspress' );
    	$data[ $label ] = implode( ', ', $teams );
    endif;
    
    if ( $past_teams ):
    	$teams = array();
    	foreach ( $past_teams as $team ):
    		$team_name = get_the_title( $team );
    		if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
    		$teams[] = $team_name;
    	endforeach;
    	$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
    endif;
    
    $data = apply_filters( 'sportspress_player_details', $data, $id );
    
    if ( sizeof( $data ) ) {
    	$output = '<div class="sp-template sp-template-player-details sp-template-details"><div class="sp-list-wrapper"><dl class="sp-player-details">';
    
    	foreach( $data as $label => $value ):
    
    		$output .= '<dd><b>' . $label . '</b> - ' . $value . '</dd>';
    
    	endforeach;
    
    	$output .= '</dl></div></div>';
    
    	echo $output;
    }
    
    /**
     * Player Profile - This displays the player biography, which is entered in the player profile box.
     *
     */
    
    $content = '<div class="sp-post-content">' . get_post_field('post_content', $id) . '<br><br></div>';
    
    // If you use shortcode in your player profile box, you must run this function to display it properly.
    echo do_shortcode($content);
    
    ?>	
    
    <?php
    /**
     * Player Statistics - Taken from the player-statistics file
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    if ( ! isset( $id ) )
    	$id = get_the_ID();
    
    $player = new SP_Player( $id );
    
    $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
    $show_total = get_option( 'sportspress_player_show_total', 'no' ) == 'yes' ? true : false;
    $leagues = get_the_terms( $id, 'sp_league' );
    
    // I filter the stats and only show Season League Stats first.  The originally coding would display both Season and Playoffs, but display it in alphabetical order (Playoffs, then Season).  This allows me to only display the Season stats first.
    
    // Loop through statistics for Season League
    if ( is_array( $leagues ) ):
    	foreach ( $leagues as $league ):
    
    	// I added this If statement to filter out anything else except for the Season stats.
             if ( $league->name == "Season" ):
    		$data = $player->data( $league->term_id );
    
    		// The first row should be column labels
    		$labels = $data[0];
    
    		// Remove the first row to leave us with the actual data
    		unset( $data[0] );
    
    		// Skip if there are no rows in the table
    		if ( empty( $data ) )
    			continue;
    
    		$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
    			'<div class="sp-table-wrapper">' .
    			'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
    
    		foreach( $labels as $key => $label ):
    			$output .= '<th class="data-' . $key . '">' . $label . '</th>';
    		endforeach;
    
    		$output .= '</tr>' . '</thead>' . '<tbody>';
    
    		$i = 0;
    
    		foreach( $data as $season_id => $row ):
    
    			$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
    
    			foreach( $labels as $key => $value ):
    				$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, 'β€”' ) . '</td>';
    			endforeach;
    
    			$output .= '</tr>';
    
    			$i++;
    
    		endforeach;
    
    		$output .= '</tbody>' . '</table>' . '</div>';
    		?>
    		<div class="sp-template sp-template-player-statistics">
    			<?php echo $output; ?>
    		</div>
    		<?php
    endif;
    	endforeach;
    endif;
    
    // I filter the stats and only show Playoff League Stats second.  The originally coding would display both Season and Playoffs, but display it in alphabetical order (Playoffs, then Season).  This allows me to only display the Playoffs stats second.
    
    // Loop through statistics for Playoff League
    if ( is_array( $leagues ) ):
    	foreach ( $leagues as $league ):
    
    	// I added this If statement to filter out anything else except for the Playoff stats.
             if ( $league->name == "Playoffs" ):
    		$data = $player->data( $league->term_id );
    
    		// The first row should be column labels
    		$labels = $data[0];
    
    		// Remove the first row to leave us with the actual data
    		unset( $data[0] );
    
    		// Skip if there are no rows in the table
    		if ( empty( $data ) )
    			continue;
    
    		$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
    			'<div class="sp-table-wrapper">' .
    			'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
    
    		foreach( $labels as $key => $label ):
    			$output .= '<th class="data-' . $key . '">' . $label . '</th>';
    		endforeach;
    
    		$output .= '</tr>' . '</thead>' . '<tbody>';
    
    		$i = 0;
    
    		foreach( $data as $season_id => $row ):
    
    			$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
    
    			foreach( $labels as $key => $value ):
    				$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, 'β€”' ) . '</td>';
    			endforeach;
    
    			$output .= '</tr>';
    
    			$i++;
    
    		endforeach;
    
    		$output .= '</tbody>' . '</table>' . '</div>';
    		?>
    		<div class="sp-template sp-template-player-statistics">
    			<?php echo $output; ?>
    		</div>
    		<?php
    endif;
    	endforeach;
    endif;
    
    //  This section shows the career stats by year.  This is originally from the coding on the main site.
    if ( $show_total ):
    	$data = $player->data( 0 );
    
    	// The first row should be column labels
    	$labels = $data[0];
    
    	// Remove the first row to leave us with the actual data
    	unset( $data[0] );
    
    	// Skip if there are no rows in the table
    	if ( empty( $data ) )
    		return false;
    
    	$output = '<h4 class="sp-table-caption">' . __( 'Career Total', 'sportspress' ) . '</h4>' .
    		'<div class="sp-table-wrapper">' .
    		'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
    
    	foreach( $labels as $key => $label ):
    		if ( 'team' == $key )
    			continue;
    		$output .= '<th class="data-' . $key . '">' . $label . '</th>';
    	endforeach;
    
    	$output .= '</tr>' . '</thead>' . '<tbody>';
    
    	$i = 0;
    
    	foreach( $data as $season_id => $row ):
    
    		$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
    
    		foreach( $labels as $key => $value ):
    			if ( 'team' == $key )
    				continue;
    			$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, 'β€”' ) . '</td>';
    		endforeach;
    
    		$output .= '</tr>';
    
    		$i++;
    
    	endforeach;
    
    	$output .= '</tbody>' . '</table>' . '</div>';
    	?>
    	<div class="sp-template sp-template-player-statistics sp-template-player-total">
    		<?php echo $output; ?>
    	</div>
    	<?php
    endif;
    
    //  This marks the end of the post content and individual player info sections.
    ?>
    
    	<footer class="entry-meta-bar clearfix">
    		<div class="entry-meta clearfix">
           	<?php edit_post_link( __( 'Edit', 'spacious' ), '<span class="edit-link">', '</span>' ); ?>
    		</div>
    	</footer>
    	<?php
    	do_action( 'spacious_after_post_content' );
       ?>
    </article>
    
    <?php /* This is the end of the main content section */ ?>
    
    				<?php
    					do_action( 'spacious_before_comments_template' );
    					// If comments are open or we have at least one comment, load up the comment template
    					if ( comments_open() || '0' != get_comments_number() )
    						comments_template();
    	      		do_action ( 'spacious_after_comments_template' );
    				?>
    
    			<?php endwhile; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    	<?php spacious_sidebar_select(); ?>
    
    	<?php do_action( 'spacious_after_body_content' ); ?>
    
    <?php get_footer(); ?>

    Basically, it is showing the content similar to the default display of the player profile from sportspress. I haven’t really modified the code to display it better. I’d like to figure out a way to filter the metrics data and be able to pull just one particular item so that I can place in in one part of the page, and design it differently than just a list style now. Still working on trying to figure out the code to do that.

    Thread Starter lstephan

    (@lstephan)

    Thanks a lot Chris,

    I will see how it works.

    Regards

    mike.chiv

    (@mikechiv)

    Luckycharm1978, you’re a f***ing lifesaver! I was searching for ages for some of the code you posted above to no avail. You’re right, the Sportspress documentation should include much more information about refined customisation of pages. I have had similar issues with lack of responses to forum posts, and have had to do a lot of the legwork myself, which is why detailed responses including usable code such as yours are invaluable!

    Many thanks πŸ™‚

    Sorry for maybe basically question, but how can I implement your code to work it in sportpress ?

    Mcholt,

    Have you followed the Plug-In integration guide?

    After you do that you should have a Sportpress folder in the Theme folder. It’s in that folder where you should have a file called single-player.php which is what the code above is used for.

    Ok, I made all steps from integration with code from my page.php qr code snipped from this topic and nothing changed in single player page. I have no idea what I’m doing wrong. After add this code I have to add some css style in my style css ?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Customize player's details page’ is closed to new replies.