简体   繁体   中英

How to auto-generate pages from an API with JavaScript on a WordPress site?

I'm using an API in JSON format to display the standings of sports teams in a league. Here's an example of the JSON data I'm working with:

{  "data":[  
  {  
     "position":1,
     "team_id":53,
     "team_name":"Celtic",
     "group_id":null,
     "group_name":null,
     "overall":{  
        "games_played":25,
        "won":18,
        "draw":6,
        "lost":1,
        "goals_scored":54,
        "goals_against":17
     },
     "home":{  
        "games_played":13,
        "won":9,
        "draw":4,
        "lost":0,
        "goals_scored":30,
        "goals_against":8
     },
     "away":{  
        "games_played":12,
        "won":9,
        "draw":2,
        "lost":1,
        "goals_scored":24,
        "goals_against":9
     },
     "total":{  
        "goal_difference":"+37",
        "points":60
     },
     "result":"Promotion - Premiership (Championship Group)",
     "points":60,
     "recent_form":"WWWDW",
     "status":"same"
  }
]}

I have a way to associate the team_ID with specific team data from the API. What I'm trying to do is to make the teams in my Standings tables clickable, so when the user clicks on a team, they can go to a page where I display data for that specific team (the info would, of course, be extracted from the API). Now, I'm developing the website on top of WordPress, and I'm wondering how I can auto-generate pages for every team, so that site users can go to specific team pages directly from the Standings tables.

It's not convenient for me to manually create pages with a piece of code and upload them to the FTP server for each team, because there'll be so many teams (eventually thousands of teams), and it's definitely not feasible.

Can anyone please guide me on the way to auto-create pages for the teams so my team links don't return 404 Not Found pages? An important point is that I'm using JavaScript to manipulate the data.

I'm using the team_id property in the API to create my team links, but I don' know how to use my team_id to automatically create team pages on my WordPress site.

Please help if you can. :)

You can use ajax method on click team-id, in ajax call function, check, is this team-id exists or not, if exists redirect to respective page or not create a new page and display require information.

I have worked same type project, I am using CPT method for the game and used the custom taxonomy for team and player.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM