我將嘗試解釋我在這里嘗試做的事情。我創建了一個名為“人物”的自定義帖子并創建了一些新帖子?,F在,我已經創建了一個帶有靜態內容的 JS 模態,它可以工作。但是,我不想在加載頁面時加載自定義帖子類型中的所有帖子,而是只想顯示每個特定 ID 的點擊模式數據。而不是在加載時有 10 或 20 個相同的模態輸出 HTML。所以點擊..我想顯示這個特定CP帖子的數據。模態人物提要 HTML(每個圖打開一個模態):<section class="feed"> <div class="container"> <div class="row content"> <h1><?php the_title(); ?></h1> <div class="feed__inner"> <figure data-post-id="1" class="feed__item"> <img class="feed__image" data-src="https://images.pexels.com/photos/1845534/pexels-photo-1845534.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" /> </figure> <figure data-post-id="2" class="feed__item"> <img class="feed__image" data-src="https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" /> </figure> <figure data-post-id="3" class="feed__item"> <img class="feed__image" data-src="https://images.pexels.com/photos/2613260/pexels-photo-2613260.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" /> </figure> <figure data-post-id="4" class="feed__item"> <img class="feed__image" data-src="https://images.pexels.com/photos/2379004/pexels-photo-2379004.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260" /> </figure>如何僅在請求/單擊時加載模態數據?
1 回答
慕斯709654
TA貢獻1840條經驗 獲得超5個贊
你可以用 AJAX 做到這一點。
創建根據 single-people.php需要輸出帖子的文件,并在彈出窗口打開時通過 ajax 請求它。
例如(假設 jquery)
<script>
function openPopup(id)
{
fetch('http://example.com?p='+id).then(
function(response){
$('#popup-content').html(response.body);
$('.popup').show();
});
}
</script>
<button onclick="openPopup(1)">Open popup #1</button>
<button onclick="openPopup(2)">Open popup #2</button>
<div class="popup">
<div id="popup-content"></div>
</div>
- 1 回答
- 0 關注
- 165 瀏覽
添加回答
舉報
0/150
提交
取消
