• mike.chiv

    (@mikechiv)


    Hi,

    As indicated by the title, this is really two separate questions.

    1: I need to show the latest result for each of the two teams in the club on my home page. Do I need to create a widget somehow, or can I just use API functions?

    2: I would also like to show segments of the two teams’ league tables on the home page. For example, if team one is top of the league I would like to show the top three positions only, and if team two is in fourth place, I would like to show positions 3, 4, and 5 in the league only. I assume that this is a little more complex to pull off, but perhaps it is possible?

    Getting on great with the plugin so far thanks to your support with previous issues. Good work!

    Mike

    https://www.ads-software.com/plugins/sportspress/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter mike.chiv

    (@mikechiv)

    Hi,

    Is anyone available to respond to my question?

    Mike

    Thread Starter mike.chiv

    (@mikechiv)

    Okay I made a little progress on point 1.

    By calling $events= new WP_Query("post_type=SP_Event"); I can pull up a list of all the existing matches. However I don’t know the names of the custom fields I need to target in order to separate out the matches for each team. The fields would be something like “team 1” and “match date” I assume (unless match date is simply, the_date();?)

    Thread Starter mike.chiv

    (@mikechiv)

    Point 1 is now solved. Code:

    <?php
    // Relevant data for every match query
    $args = array(
    	'post_type' => 'SP_Event',
    	'orderby' => 'date',
    	'showposts' => 1,
    	'meta_key' => 'sp_team',
    	'meta_compare' => '='
    );
    
    // Add data to get previous matches only and prepare arrays for first and reserve team latest matches
    $args_l = $args;
    $args_l['post_status'] = 'publish';
    $args_l['order'] = 'desc';
    $args_fl = $args_l;
    $args_rl = $args_l;
    
    // Add data to get next matches only and prepare arrays for first and reserve team next matches
    $args_n = $args;
    $args_n['post_status'] = 'future';
    $args_n['order'] = 'asc';
    $args_fn = $args_n;
    $args_rn = $args_n;
    
    // Apply team ID to each recent match array (to make meta compare work) and run WP_Query on each
    $args_fl['meta_value'] = 172;
    $args_rl['meta_value'] = 213;
    $first_team_latest_result = new WP_Query($args_fl);
    $reserves_latest_result = new WP_Query($args_rl);
    
    // Apply team ID to each upcoming match array (to make meta compare work) and run WP_Query on each
    $args_fn['meta_value'] = 172;
    $args_rn['meta_value'] = 213;
    $first_team_next_match = new WP_Query($args_fn);
    $reserves_next_match = new WP_Query($args_rn);
    
    // Merge all team queries into one array
    //For some reason the_loop() won't work on $matches, so I had to use a for loop and various functions to get the data
    //required. See below.
    $matches = new WP_Query();
    
    $matches = array_merge( $first_team_latest_result->posts, $reserves_latest_result->posts, $first_team_next_match->posts, $reserves_next_match->posts);
    
    $matches->post_count = $first_team_latest_result->post_count + $reserves_latest_result->post_count;	
    
    ?>
    <section id="latest-results" class="fixtures">
    		<header>
    			<h1 class="column-title">Latest results</h1>
    			<hr>
    		</header>
    		<?php for($i=0; $i<2; $i++){
    			if( !$matches[$i] ) { continue; };
    			$current_id = $matches[$i]->ID;
    			$teams = sp_get_teams($current_id);
    			$logos = null;
    			foreach($teams as $team){
    				$logos[] = sp_get_logo($team);
    			}
    			$match_date = mysql2date("l, jS M Y", $matches[$i]->post_date) . " - " . sp_get_time($current_id);
    			$scores = sp_get_main_results($current_id);
    			$link = get_the_permalink($current_id);
    			?>
    			<section class="match-container">
    				<a href="<?php echo $link; ?>" class="anchor-overlay"></a>
    				<h2><a href="<?php echo $link; ?>"><?php echo get_the_title($matches[$i]); ?></a></h2>
    				<p class="match-date"><?php echo $match_date; ?></p>
    				<div class="group match-result-and-logos">
    					<div class="logo1"><?php echo $logos[0]; ?></div>
    					<h3 class="match-score"><span class="match-score-number"><?php echo $scores[0]; ?></span><span class="match-score-delimeter">-</span><span class="match-score-number"><?php echo $scores[1]; ?></span></h3>
    					<div class="logo2"><?php echo $logos[1]; ?></div>
    				</div>
    			</section>
    		<?php } ?>
    	</section><!-- latest results -->
    	<section id="next-matches" class="fixtures">
    		<header>
    			<h1 class="column-title">Next matches</h1>
    			<hr>
    		</header>
    		<?php for($i=2; $i<4; $i++){
    			if( !$matches[$i] ) { continue; };
    			$current_id = $matches[$i]->ID;
    			$teams = sp_get_teams($current_id);
    			$logos = null;
    			foreach($teams as $team){
    				$logos[] = sp_get_logo($team);
    			}
    			$match_date = mysql2date("l, jS M Y", $matches[$i]->post_date) . " - " . sp_get_time($current_id);
    			$link = get_the_permalink($current_id);
    			?>
    			<section class="match-container">
    				<a href="<?php echo $link; ?>" class="anchor-overlay"></a>
    				<h2><a href="<?php echo $link; ?>"><?php echo get_the_title($matches[$i]); ?></a></h2>
    				<p  class="match-date"><?php echo $match_date; ?></p>
    				<div class="group match-result-and-logos">
    					<div class="logo1"><?php echo $logos[0]; ?></div>
    					<p class="versus"><strong>VS</strong></p>
    					<div class="logo2"><?php echo $logos[1]; ?></div>
    				</div>
    			</section>
    		<?php } ?>
    	</section><!-- next matches -->

    Still need help with point 2, though.

    Thread Starter mike.chiv

    (@mikechiv)

    …or if you don’t want to cram in a huge block of unnecessary code, you can set up your calendars properly and use the very simple Sportspress shortcodes as described in this post.

    D’oh!

    Thread Starter mike.chiv

    (@mikechiv)

    Plugin author/s, do you have any suggestions for point 2 in the OP?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display latest result only and show a segment of the league table’ is closed to new replies.