因此,我正在制作一个页面,当用户单击特定的公文包滑块时,页面上将显示多个公文包项目,并显示该公文包类别上的图像。
因此,我从URL(#哈希标记)传递值
    <div class="portfolio1">
        <a href="#/branding">
            <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150"/>
            <h2>Branding</h2>
                </a>
        </div>
        <div class="portfolio2">
        <a href="#/logo">
            <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150"/>
            <h2>Logos</h2>
                </a>
        </div>  <div id="content2"></div>
<?php $args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 12,
\'tax_query\' => array(
    array(
        \'taxonomy\' => \'category\',
        \'field\' => \'slug\',
        \'terms\' => \'logo\'
    )
 }?>
 现在,我想当用户单击公文包时,将包含类别slug的a href传递给WP查询(“术语”)
我的Ajax脚本
jQuery(\'#portfolio div a\').click(function () {
var hash = window.location.hash;
jQuery.ajax({
          type: "POST",
    url: \'http://localhost/final/ajax.php\',
     data: {\'hash\': hash},
    success: function(data){
        jQuery(\'#content2\').html(data);
    }
});});
 Ajax。php文件
<?php 
$hash = $_GET[\'hash\'];
$hash = str_replace(\'#\', \' \', $hash);
echo $hash;?>
 任何帮手。
 
                SO网友:Divyesh Tailor
                创建简单的函数,如
function func_for_ajax(){
    wp_localize_script( \'ajax_custom_script\', \'frontendajax\', array( \'ajaxurl\' => admin_url( \'admin-ajax.php\' )));
    echo "simple demo ajax";
 }
然后在wordpress中创建ajax传递操作直接抛出此函数名。
jQuery.ajax({
     type: "POST",
     action: \'func_for_ajax\',
     url: \'ajaxurl\',
     success: function(data){
       jQuery(\'#content2\').html(data);
     }
 });