1 回答

TA貢獻1824條經驗 獲得超5個贊
您不需要為此目的添加隱藏按鈕,也不需要添加 jQuery 代碼。當頁面加載時,您的 API 已經被調用并且結果已經存在,以便在頁面加載 UI 之前呈現。所以我們需要遍歷從 API 接收到的數據并呈現 UI。
試試下面的代碼塊:
<?php
global $user_ID, $user_identity, $userdata; wp_get_current_user();
$current_user = wp_get_current_user();
$custemail= $current_user->user_email;
get_header();
$url = 'https://httpapi.com/api/customers/details.json?auth-userid=12345&api-key=mykey&username='.$custemail;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
if(curl_error($ch)) {
echo 'error:' . curl_error($ch);
};
curl_close($ch);
$data = json_decode($json,true);
$custid = $data['customerid'];
$url = 'https://httpapi.com/api/domains/search.json?auth-userid=12345&api-key=mykey&no-of-records=10&page-no=1&customer-id='.$custid;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
if(curl_error($ch)) {
echo 'error:' . curl_error($ch);
};
curl_close($ch);
$data = json_decode($json,true);
ksort($data);
?>
<div>
<ul id="dom-list" class="domain-list-ul">
<?php foreach($data as $key => $value) { ?>
<?php if(is_array($value)) { ?>
<li>
<p class="tld-name-2">
<?php echo " {$value['entity.description']}"; ?>
</p>
<p class="prop">
<span class="prop-head">Created On :</span>
<span class="data-no"><?php echo " {$value['orders.creationtime']}"; ?></span>
</p>
<p class="prop">
<span class="prop-head">Expires On :</span>
<span class="data-no"><?php echo " {$value['orders.endtime']}"; ?></span>
</p>
<p class="prop">
<span class="prop-head">Privacy Protection :</span>
<span class="data-no"><?php echo " {$value['orders.privacyprotection']}"; ?></span>
</p>
<p class="prop">
<span class="prop-head">Theft Protection :</span>
<span class="data-no"><?php echo " {$value['orders.customerlock']}"; ?></span>
</p>
<p class="prop">
<span class="prop-head">Status :</span>
<span class="data-no"><?php echo " {$value['entity.currentstatus']}"; ?></span>
</p>
</li>
<?php }
} ?>
</ul>
</div>
- 1 回答
- 0 關注
- 174 瀏覽
添加回答
舉報