WordPress.org

Ready to get started?Download WordPress

Forums

LeagueManager
[resolved] How can I add stats field to matches tables? (4 posts)

  1. klangrud
    Member
    Posted 2 years ago #

    Here is the page where I have the league schedule:
    http://tcadulthockey.com/wp/schedule/

    I'm using the matches shortcode:
    [matches league_id=1 mode=all]

    I have added a stat for each match called referee. I would like this information to be displayed on the matches table page above. Is there a way to add this to the matches shortcode or will I have to create a custom template?

    http://wordpress.org/extend/plugins/leaguemanager/

  2. klangrud
    Member
    Posted 2 years ago #

    I resolved this by creating my own template from matches.php. I pulled code from template match.php and added it into my new matches.php template. In the following code you just need to change $stat->name to the name of your stat. Here is the snippet:

    <td>
              <?php if ( isset($match->hasStats) && $match->hasStats ) :?>
                <?php foreach ( $lmStats->get($match->league_id) AS $stat ) : ?>
    
                  <?php if ( isset($match->{sanitize_title($stat->name)}) ) : ?>
                    <?php foreach ( (array)$match->{sanitize_title($stat->name)} AS $i => $data ) : ?>
                      <?php foreach ( (array)maybe_unserialize($stat->fields) AS $field ) : ?>
                        <?php if ( isset($match->{sanitize_title($stat->name)}) && $stat->name == 'Referee' ) : ?>
                          <?php echo $data[sanitize_title($field['name'])] ?>
                          <br />
                        <?php endif; ?>
                     <?php endforeach; ?>
                   <?php endforeach; ?>
                 <?php endif; ?>
    
               <?php endforeach; ?>
             <?php endif; ?>
            </td>
  3. bjonesilg
    Member
    Posted 2 years ago #

    Hi klangrud,

    This seems very similar to what I want to achieve. I am editing the matches.php template to show a new column called Match Report which takes the stat field called "URL" from the stat name "report". I've tried using your code but can't seem to get it to work. The end game really that the url field simply holds a link to a post, this link then gets pulled in to the href and wrapped around the word "view" (only if there is anything in the url field, otherwise it should display nothing. Any ideas how I can achieve this?

  4. klangrud
    Member
    Posted 1 year ago #

    Hi bjonesilg,

    I just saw your question. I don't know if you are still trying to figure this out but I might be able to help you.

    Change what I have from:

    <?php if ( isset($match->{sanitize_title($stat->name)}) && $stat->name == 'Referee' ) : ?>
      <?php echo $data[sanitize_title($field['name'])] ?>
       <br />
    <?php endif; ?>

    To:

    <?php if ( isset($match->{sanitize_title($stat->name)}) && $stat->name == 'report' ) : ?>
      <?php if ( isset($data[sanitize_title('URL')])) : ?>
        <a href="<?php echo $data[sanitize_title($field['name'])] ?>">URL</a>
        <br />
      <?php endif; ?>
    <?php endif; ?>

    Let me know how that works for you and if you have any questions.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic