• Resolved itsDarkangel

    (@itsdarkangel)


    Hello,

    Still loving the plugin. Well into our 4th season in conjunction with sportspress. I was hoping you could tell me how I could add a box to show recent game results. I would hope to include Team name and Goals for reach team and then maybe highlight the winner in bold if we wanted to get fancy, but that’s an afterthought.

    Formatting it afterwards probably wouldn’t be too difficult, but I was wondering how I could go about setting a loop to pull recent event results so the it wouldn’t need to be edited after each game.

    We’re basically eventually going to shoot for something similar to what espn.com has at the top.

    Thanks!

    site is: https://www.zealothockey.net/

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

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Brian

    (@brianmiyaji)

    @itsdarkangel Glad to hear you’re enjoying the plugin! Here’s some code that gets the last 5 events, loops through them and outputs some basic HTML to get you started:

    // Define args
    $args = array(
    	'numberposts' => 5,
    	'post_type' => 'sp_event',
    	'post_status' => 'publish'
    );
    
    // Get events
    $events = get_posts( $args );
    
    // Loop through events
    foreach ( $events as $event ) {
    	// Get event results
    	$results = sp_get_results( $event->ID );
    
    	// Loop through teams in the event
    	foreach ( $results as $team_id => $team_results ) {
    		if ( 0 == $team_id ) continue; // Skip the labels
    		?>
    		<div class="mywidget-team">
    			<span class="mywidget-team-name"><?php echo get_the_title( $team_id ); ?></span>
    			<span class="mywidget-team-results">
    				<?php foreach ( $team_results as $key => $result ) { ?>
    					<?php if ( 'outcome' == $key ) continue; // Skip outcome arrays ?>
    					<span class="mywidget-team-result"><?php echo $result; ?></span>
    				<?php } ?>
    			</span>
    		</div>
    		<?php
    	}
    }
    Roch

    (@rochesterj)

    @itsdarkangel

    We haven’t heard back from you, did this code help you? Please let us know if you still need any help!

    And if it’s resolved, please set it as resolved and consider showing your support by leaving us a review ??

    Kind Regards,
    -Roch

    Roch

    (@rochesterj)

    @itsdarkangel

    One more bump, please let us know if you need anything else!

    Kind Regards,
    -Roch

    Thread Starter itsDarkangel

    (@itsdarkangel)

    This project was actually put on hold, sadly. We didn’t get a chance to try this out since our season started and things got a bit hectic ??

    I appreciate you checking in, though.

    -Dark

    Roch

    (@rochesterj)

    Hi!

    Please set this one as resolved then, it really helps us a lot!

    Kind Regards,
    -Roch

    Thread Starter itsDarkangel

    (@itsdarkangel)

    Done.

    Thread Starter itsDarkangel

    (@itsdarkangel)

    Actually, I’ve started looking into this, again. I guess I’m just a little bit confused on where I would use this code. Should this be placed directly into a php file? If so, how would I access it in a regular page? Or is this supposed to be something I could place directly into a page once I get the correct <?php ?> connotation. (The code Brian gave me starts off in PHP language, but doesn’t open with <?php ?>.

    I’m currently running through codeacademy lessons again to try and figure this out myself, but any help would still be very much appreciated. I’ll be checking back to this post a fair amount.

    Thread Starter itsDarkangel

    (@itsdarkangel)

    Or would I need to make a new .php document and insert this code? then try to call it when i’m actually editing pages?

    Roch

    (@rochesterj)

    Hi!

    That snippet is just the loop itself. To call it in a page you can either add it as a shortcode (the easiest option IMHO) or create a new page template, for example and include that code there.

    https://codex.www.ads-software.com/Shortcode_API
    https://developer.www.ads-software.com/themes/template-files-section/page-template-files/page-templates/

    Kind Regards,
    -Roch

    Thread Starter itsDarkangel

    (@itsdarkangel)

    Thanks! This is starting to make a lot more sense now! I’ll give you an update once we give this a full-scale try.

    Roch

    (@rochesterj)

    Great!

    Let me know if you need anything else in the meantime!

    Kind Regards,
    -Roch

    Roch

    (@rochesterj)

    Since we haven’t heard back from you, I’ll set this one as resolved.

    Please, let us know if you need anything else.

    Kind Regards,
    -Roch

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Recent Game Results’ is closed to new replies.