我正在尝试通过从网站上删除数据并发布它来创建我的第一个wordpress短代码。但是,我有问题连接PHP循环与我的HTML代码,然后返回HTML。我想在每次执行循环时创建一行并将opp1,opp2和score放在表中然后重新调整html脚本
<table class="match-table" cellspacing="0" cellpadding="0">
<tbody>
<tr class="margin-tr">
<td class="match-icon">Icon</td>
<td class="match-home">Opp1</td>
<td class="match-score">score</td>
<td class="match-away">opp2</td>
<td class="match-time">22:00</td>
</tr>
</tbody>
</table>
PHP:
function getGames() {
$html = str_get_html(getHTML($url,10));
//$title = str_replace(array("\n", "\r"), '',$html->find("/[@id='main']/div[1]/div[2]/div[1]/h2/strong",0)->plaintext);
//$manuf = $html->find("/[@id='main']/div[1]/div[2]/div[3]/table/tbody/tr[1]/td[2]/strong",0)->plaintext;
$table = $html->find("/[@id='matches_list']/",0);
foreach($table->find("li") as $line){
$game = $line->find("a/span/img",0)->title;
if( $game == "CS:GO" or $game == "Hearthstone" or $game == "Dota 2" or $game == "StarCraft II" or $game == "League of Legends"){
$opp1 = $line->find("span.opp1",0)->plaintext;
$opp2 = $line->find("span.opp2",0)->plaintext;
$score = $line->find("span.score",0)->plaintext;
}
}
}
add_shortcode('getGames', 'getGames');