简体   繁体   English

如何在WordPress网站上使用JavaScript从API自动生成页面?

[英]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. 我正在使用JSON格式的API来显示联赛中运动队的排名。 Here's an example of the JSON data I'm working with: 这是我正在使用的JSON数据的示例:

{  "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. 我有一种方法可以将team_ID与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). 我想做的是使我的排名表中的团队可点击,因此当用户单击某个团队时,他们可以转到一个页面,在该页面上我可以显示该特定团队的数据(当然,信息会是从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. 现在,我正在基于WordPress开发网站,并且想知道如何为每个团队自动生成页面,以便站点用户可以直接从Standings表中转到特定的团队页面。

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. 对于我来说,手动编写带有一段代码的页面并将其上载到每个团队的FTP服务器上并不方便,因为会有如此多的团队(最终是数千个团队),这绝对是不可行的。

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? 谁能指导我为团队自动创建页面的方式,以便我的团队链接不会返回404 Not Found页面? An important point is that I'm using JavaScript to manipulate the data. 重要的一点是,我正在使用JavaScript来处理数据。

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. 我在API中使用team_id属性创建团队链接,但是我不知道如何使用team_id在WordPress网站上自动创建团队页面。

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. 您可以在ajax调用函数中的单击team-id上使用ajax方法,检查此team-id是否存在,如果存在则重定向到相应页面或不创建新页面并显示需要的信息。

I have worked same type project, I am using CPT method for the game and used the custom taxonomy for team and player. 我曾经从事过相同类型的项目,我在游戏中使用CPT方法,并为团队和玩家使用了自定义分类法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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