jbarker147
Forum Replies Created
-
You can add a shortcode into the tab, but if you’re using tablepress then it won’t know which player to display because they won’t be linked – it’ll always show the full table. I only ever had tablepress show the full list on the overall breaks page.
The player-breaks file can use any shortcode, but that’s what the existing tabs are there for (for example, player details, statistics, fixtures, etc) so there’s no need to use shortcodes. The extra tabs are really for additional information outside of what Sportspress does, such as breaks, and achievements/roll of honour, etc.
I previously used Tablepress (I think you suggested it a few years ago!) but I changed to Advanced Custom Fields which I’ve set up to add a Breaks section in each event/fixture. This uses a dropdown to search for the players, then enter the break, and add as many rows as needed. All of that data is then stored in the database and can be queried.
https://snipboard.io/ucA78t.jpg
My player-breaks file searches through the database for all events/fixtures and looks to see if any breaks have been recorded. Then it will check if that player matches the player who’s page you are looking at, and if it does then it’ll add it to the table with a link to the fixture in which it happened.
https://snipboard.io/W6adFm.jpg
It took a lot of work and hours to get the code right, and I’m still looking at ways of improving it especially as our data only goes back to 2016/17 at the moment but I’m looking to put more on from as far back as around 1992.
Hi @kev147
Each of our player profiles display their own breaks, so I can see my own individually. I’ve got it set up for a Roll of Honour too, just putting the data in first.
That’s right. Replace <div>test</div> with whatever you need to display in that section.
What’s the contents of your player-breaks.php file?
For testing purposes, use this…
<?php /** * Player Breaks **/ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( get_option( 'sportspress_player_show_breaks', 'yes' ) === 'no' ) return; if ( ! isset( $id ) ) $id = get_the_ID(); ?> <div>test</div> <?php
Now when you click on the Breaks tab, you should only see the word test.
Hi @kev147
First of all, the functions.php file shouldn’t be inside the sportspress folder. It needs to be directly inside the child theme.
In your screenshot HERE delete the bit about ‘anothertab’ – that was put there as an example to show how to add extra tabs.
Looking at the code you’ve pasted, change your functions.php to this…
<?php // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; // BEGIN ENQUEUE PARENT ACTION // AUTO GENERATED - Do not modify or remove comment markers above or below: if ( !function_exists( 'chld_thm_cfg_parent_css' ) ): function chld_thm_cfg_parent_css() { wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'rookie-framework-style' ) ); } endif; add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 ); if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 150, 150, true ); // default Post Thumbnail dimensions (cropped) } // END ENQUEUE PARENT ACTION function sportspress_output_player_breaks() { sp_get_template( 'player-breaks.php' ); } add_filter( 'sportspress_after_player_template', 'add_tabs'); function add_tabs() { $insert = array( 'statistics' => array( 'title' => __( 'Statistics', 'sportspress' ), 'option' => 'sportspress_player_show_statistics', 'action' => 'sportspress_output_player_statistics', 'default' => 'yes', ), 'breaks' => array( 'title' => __( 'Breaks', 'sportspress' ), 'option' => 'sportspress_player_show_breaks', 'action' => 'sportspress_output_player_breaks', 'default' => 'yes', ), ); return $insert; }
This is based on you having the player-breaks.php file inside the sportspress folder.
Hi @kev147
The functions.php should be inside the child theme. Never edit the file inside the main folder because any changes you make will get overwritten when there’s an update.
Add the code anywhere in the file. I usually add mine to the bottom and put a comment above it as a title for easy finding.
In your child theme, you should have a folder called ‘sportspress’ (make one if there isn’t one). This is where you need to put your player-breaks.php file.
While you’re experimenting with it, I wouldn’t suggest copying the entire code of the single-event file. I would just put in a piece of text for testing to show it’s working, then go back afterwards to create the template properly.
Hi Roch
I’ve spent a few hours today working it out. I had just finished shortly after you replied – turns out it really only needed a couple of bits adding to the functions.php
If anybody is reading this and would like to know how to do it…
For the purposes of this, I’m creating a new tab called ‘Breaks’ on to my player profile page.
1. Create a template called player-breaks.php and add it to your Sportspress folder (in the child theme). This should be named ‘player-‘ followed by its name. Remember to leave the <?php open at the end of the file.
2. Create a function to retrieve your template. Add the following code to your functions.php file:
function sportspress_output_player_breaks() { sp_get_template( 'player-breaks.php' ); //name of your template }
3. Add a filter to replace the existing function. Add the following code to your functions.php file:
add_filter( 'sportspress_after_player_template', 'add_tabs'); function add_tabs() { $insert = array( 'statistics' => array( 'title' => __( 'Statistics', 'sportspress' ), 'option' => 'sportspress_player_show_statistics', 'action' => 'sportspress_output_player_statistics', 'default' => 'yes', ), 'breaks' => array( 'title' => __( 'Breaks', 'sportspress' ), 'option' => 'sportspress_player_show_breaks', 'action' => 'sportspress_output_player_breaks', 'default' => 'yes', ), //repeat as necessary 'anothertab' => array( 'title' => __( 'Another Tab', 'sportspress' ), 'option' => 'sportspress_player_show_anothertab', 'action' => 'sportspress_output_player_anothertab', 'default' => 'yes', ), ); return $insert; }
4. Go to your Settings -> Player page in the admin to see your new items, ready for you to move where you need and turn on and off.
Hope this helps anybody trying!
Forum: Plugins
In reply to: [SportsPress - Sports Club & League Manager] Games TallyHi Roch,
Thanks for the reply!The code I’ve got is below – it loops through each published event and adds the scores together – the only thing missing is how to reference the home team score and the away team score for the post. I was hoping it was something as simple as sp_result_home and sp_result_away but it doesn’t look like that’s possible. There must be a way to query them, because they show on the event result, but I can’t seem to find how to do it.
Any advice?
$args = array( 'post_type' => 'sp_event', 'status' => 'publish', 'posts_per_page'=>'-1' ); $query_frames = new WP_Query($args); $framescount = 0; if( $query_frames->have_posts() ) : while( $query_frames->have_posts() ) : $query_frames->the_post(); $homescore = ???; $awayscore = ???; $framescount = $framescount + $homescore + $awayscore; endwhile; endif; echo $framescount; wp_reset_query();
Forum: Plugins
In reply to: [SportsPress - Sports Club & League Manager] Team Name ChangeThanks for your suggestion. It would also need to be past fixtures I’m afraid. If that’s the only way that it can be done, then I guess we’ll have to just do it that way and unfortunately lose the data for the past fixtures.
That’s done the trick – thank you very much!
I removed it completely to make sure it didn’t interfere with the new code.
What is the ‘true’ variable used for? I wonder if it’s a setting I’ve got in my teams or tables which causes it to do this?
@savvasha, unfortunately that only returned a 0 and nothing else.
That’s what I was looking for! Thank you so much!
For anybody interested, here’s what I did to display the team names along with the image and link (obviously needs styling correctly).
$teams = get_post_meta(123, 'sp_team'); // 123 is the post ID of the League Table $teams2 = array_shift($teams); // My array was producing a zero to begin with, so this removes it foreach ( $team as $item) : // For each team in this table, do the following echo the_permalink($item); // Displays the link url echo get_the_post_thumbnail_url($item); // Displays the url of the team logo echo get_the_title($item); // Displays the team name endforeach; // Finish
Hi Savvas,
Thanks for your reply.That’s what I already do for the league tables – what you’re suggesting for me to do is exactly what I’m trying, but I can’t seem to get the code to call the teams through. Would you be able to help with that please?
Thank you.