• Resolved ibeats

    (@ibeats)


    I’m trying to get the Current Team name in the post title, under Player Details — as a kind of breadcrumb.

    By tweaking sp-template-hooks.php, I’ve been able to do something. But its not perfect. I suspect I’m looking in the wrong place/barking up the wrong tree.

    Any advice?

    function sportspress_the_title( $title, $id = null ) {
    if ( ! $id ) {
    return $title;
    }

    if ( ! is_admin() && in_the_loop() && $id == get_the_ID() ) :
    if ( is_singular( 'sp_player' ) ) :
    $number = get_post_meta( $id, 'sp_number', true );
    $current_team = get_post_meta( $id, 'sp_team', true );
    $url = get_post_meta( $id, 'sp_url', true );
    if ( $number != null ) :
    $title = '<strong class="sp-player-number">' . $number . '</strong> ' . $title . ' | ' . '<a href="' . $url . '">' . $current_team . '</a>';
    endif;
    elseif ( is_singular( 'sp_staff' ) ) :
    $staff = new SP_Staff( $id );
    $role = $staff->role();
    if ( $role ) {
    $title = '<strong class="sp-staff-role">' . $role->name . '</strong> ' . $title;
    }
    endif;
    endif;

    return $title;
    }
    add_filter( 'the_title', 'sportspress_the_title', 10, 2 );

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Savvas

    (@savvasha)

    Hi there @ibeats ,

    Current team of a player is saved as post-meta with key sp_current_team. So you retrieve it using the function get_post_meta().

    i.e.
    //Retrieve current team ID
    $current_team_id = get_post_meta( your_player_id, 'sp_current_team', true );
    //Get team name
    $current_team_name = get_the_title( $current_team_id );

    The above code can be used with filter the_title so as to add the team name next to player’s name.

    Thanks,
    Savvas

    Thread Starter ibeats

    (@ibeats)

    Thank you for your rapid response @savvasha! No such luck – though my brain is fried, its Friday after all ??

    function sportspress_the_title( $title, $id = null ) {
    if ( ! $id ) {
    return $title;
    }

    if ( ! is_admin() && in_the_loop() && $id == get_the_ID() ) :
    if ( is_singular( 'sp_player' ) ) :
    $number = get_post_meta( $id, 'sp_number', true );
    $current_team = get_post_meta( $id, 'sp_current_team', true );
    $team_name = get_post_title( $current_team );

    $url = get_post_meta( $id, 'sp_url', true );
    if ( $number != null ) :
    $title = '<strong class="sp-player-number">' . $number . '</strong> ' . $title . ' | ' . '<a href="' . $url . '">' . $team_name . '</a>';
    endif;
    elseif ( is_singular( 'sp_staff' ) ) :
    $staff = new SP_Staff( $id );
    $role = $staff->role();
    if ( $role ) {
    $title = '<strong class="sp-staff-role">' . $role->name . '</strong> ' . $title;
    }
    endif;
    endif;

    return $title;
    }
    add_filter( 'the_title', 'sportspress_the_title', 10, 2 );

    $current_team = get_post_meta( $id, ‘sp_current_team’, true ); correctly returns the Team ID, but I cannot get the Team Name from that :S

    Plugin Contributor Savvas

    (@savvasha)

    Hi @ibeats ,

    You must not edit core plugin files. Otherwise on each plugin update your changes will be lost! You will need to add your custom function to your-child-theme functions.php file.

    Use get_the_title() function. get_post_title() does not exist.

    Thanks,
    Savvas

    Thread Starter ibeats

    (@ibeats)

    Thanks again @savvasha… in relation to “copying” core plugin components to a child theme… does this only apply to template components of a plugin, or for example, can the “includes” components also be copied to the child for modification?

    For example, root/wp-content/plugins/sportspress/includes/sp-template-hooks.php, where would this be copied to, in a child theme for manipulation?

    I’ve tried root/wp-content/themes/theme-child/sportspress/includes/sp-template-hooks.php and also root/wp-content/themes/theme-child/sportspress/sp-template-hooks.php to no avail ??

    Do core components not work like that?

    • This reply was modified 7 months, 1 week ago by ibeats.
    Plugin Contributor Savvas

    (@savvasha)

    Hi @ibeats ,

    See below for more info about integrating SportsPress to your theme
    https://support.themeboy.com/category/336-developers

    In general, you can use the following:

    1. Copy sportspress template files from /plugins/sportspress/templates/ to /themes/your_child_theme/sportspress/ and alter them as you want.
    2. Use the available hooks (actions and filters) of SportsPress at themes/your_child_theme/functions.php

    Thanks,
    Savvas

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Team Name & Permalink in Post Title’ is closed to new replies.