Extra Tabs on Player or Team Pages
-
Hi guys
Is it possible to create additional tabs on the player and team pages?
https://snipboard.io/HVEy4x.jpg
I’ve got a few custom post types which I want to include as a tab (for example, Achievements, Breaks) but I can’t see where I can go to add them.
Thanks in advance.
-
Hi!
Thanks for your message.
Unfortunately at the moment we don’t have a backend option for this. You’ll need some custom code to add custom tabs there.
Thanks!
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!
I am very very interested in this for “breaks” myself, if i get stuck can i respond here for some questions please ?
Thanks KevRight confused already,
I copied single-event.php and re-named it player-breaks.php added to sportspress folder inside theme rookie.
looking for functions.php i see a few which one is it rookie child theme or rookie main folder.?
and where do i add this code anywhere inside the file? please bare in mind i know diddly about web coding
ThanksHi @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.
For people not confident creating files (and child themes), a very nice alternative is to use the plugin Code Snippets to add the code to your website.
Hi Nabil, i have tried adding the two codes provided above by the kind @jbarker147 and it made my site go crazy seen HERE and THIS was the outcome
@jbarker147 what i cant understand is you say both codes go into the same functions file ?
This is what i have inside functions.php within child-theme/sportspress<?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: function sportspress_output_player_breaks() { sp_get_template( 'player-breaks.php' ); //name of your template } 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
Sorry just cant understand how to do this lol
kev
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.
I apprentice your time @jbarker147 really i do, regards to the another tab i would like to leave that if possible as i have much need for a few tabs.
Now back to my headache..
I included the new code and what happens is some kind of loop with the profile, HERE is a image if you look at top right red arrow showing you can see how many times its looped the same profile
and when you click breaks THIS is what it shows some strange things happening with the sidebar widgets.
The tabs are visible now just something messing it up?Thanks kev
- This reply was modified 5 years, 2 months ago by kev147.
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.
Brilliant that works, everything looks normal with the word test in breaks ??
The content of my file looked nothing like the above lol
Thanks alot
@jbarker147- This reply was modified 5 years, 2 months ago by kev147.
I can see how you have added “test” if i was to add a link is that where i would place it.
I think looking at this with eyes open its beyond my scope, i have one file called player-breaks and can see the word test inside.
I dont know how i would get different breaks inside each profile because test is shown on everyones and i guess whatever i include will show on everyones tab?thanks
- This reply was modified 5 years, 2 months ago by kev147.
That’s right. Replace <div>test</div> with whatever you need to display in that section.
Have you been able to add different stuff to different profiles?
As you said above changing the test to whatever shows perfectly but really need to find a way to add different breaks to each profiles of you get my meaning.Is this even possible?
I’d love to be able to use “another tab” for achievements titles etc too this I’ll exponent with later.
Cheers kev
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.
- The topic ‘Extra Tabs on Player or Team Pages’ is closed to new replies.