亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在單擊時使用 jQuery 動態加載 WordPress 自定義帖子類型數據?

如何在單擊時使用 jQuery 動態加載 WordPress 自定義帖子類型數據?

PHP
UYOU 2022-01-02 16:29:37
我將嘗試解釋我在這里嘗試做的事情。我創建了一個名為“人物”的自定義帖子并創建了一些新帖子?,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>


查看完整回答
反對 回復 2022-01-02
  • 1 回答
  • 0 關注
  • 165 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號