Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 分页don';不显示何时使用ajax_Php_Jquery_Html_Ajax_Wordpress - Fatal编程技术网

Php 分页don';不显示何时使用ajax

Php 分页don';不显示何时使用ajax,php,jquery,html,ajax,wordpress,Php,Jquery,Html,Ajax,Wordpress,我创建了一个ajax,一切都很好。但是当ajax工作时,分页并不显示。它消失了。 这是我的密码。 pagehome.php <div class="resul-ajax"> <ul class="names-results listing-view" id=":0.nr" style="-webkit-user-select: none;"> <?php

我创建了一个ajax,一切都很好。但是当ajax工作时,分页并不显示。它消失了。 这是我的密码。 pagehome.php

<div class="resul-ajax">
                    <ul class="names-results listing-view" id=":0.nr" style="-webkit-user-select: none;">
                        <?php
                        $args = array(
                            'posts_per_page' => 10,
                            'post_type' => 'baby_name',
                            'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
                            'orderby' => 'title',
                            'order' => 'ASC',
                        );
                        query_posts($args);
                        ?>

                        <?php
                        $i = 0;
                        while (have_posts()) : the_post();
                            ?>
                            <?php
                            $terms = get_the_terms($post->ID, 'gender');
                            $gender = array();
                            foreach ($terms as $term) {
                                $gender[] = $term->name;
                            }
                            ?>

                            <li <?php
                        if ($i == 0) {
                            echo 'class="old"';
                            $i = 1;
                        } else {
                            echo 'class="even"';
                            $i = 0;
                        }
                            ?>>
                                <a href="<?php the_permalink(); ?>">
                                    <?php
                                    if ($gender[0] == 'Male') {
                                        echo "<span class='result-gender boy'></span>";
                                    } elseif ($gender[0] == 'Female') {
                                        echo "<span class='result-gender girl'></span>";
                                    } else {
                                        echo "<span class='result-gender boygirl'></span>";
                                    }
                                    ?>
                                    <span class="result-name"><?php echo get_the_title(); ?></span>
                                    <span class="result-desc"></span>
                                </a>
                            </li>
                            <?php
                        endwhile;
                        ?>
                    </ul>
                    <section class = "pagination">
                        <?php emm_paginate(); ?>
                        <?php
                        wp_reset_query();
                        ?>
                    </section>
                </div>
这是我的function.php

function query_homepage() {
    wp_enqueue_script('ajax-script', get_stylesheet_directory_uri() . '/library/js/ajax-query.js', array('jquery'), 1.0); // jQuery will be included automatically
    wp_localize_script('ajax-script', 'ajax_object', array('ajaxurl' => admin_url('admin-ajax.php'))); // setting ajaxurl
}

add_action('init', 'query_homepage');

function ajax_action_stuff() {
    // getting variables from ajax post
    $startwith = $_POST['startwith'];
    $male = $_POST['male'];
    $female = $_POST['female'];
    $field3 = $_POST['field3'];
    $field3vl = $_POST['field3vl'];
    $page = $_POST['page'];
    if ($male != "" && $female != "") {
        $gender = array("both-names", $female, $male);
    } elseif ($male != "") {
        $gender = $male;
    } elseif ($female != "") {
        $gender = $female;
    }
    $args = array(
        'post_type' => 'baby_name',
        'posts_per_page' => 10,
        'paged' => $page,
        'orderby' => 'title',
        'order' => 'ASC',
    );
    if ($startwith == '' && $field3 == '') {
        $args['tax_query'][] = array(
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
        );
    } elseif ($startwith == '') {
        $args['tax_query'][] = array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
            array(
                'taxonomy' => $field3,
                'field' => 'slug',
                'terms' => $field3vl,
            ),
        );
    } elseif ($field3 == '') {
        $args['tax_query'][] = array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
            array(
                'taxonomy' => 'starts-with',
                'field' => 'slug',
                'terms' => $startwith,
            ),
        );
    } else {
        $args['tax_query'][] = array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
            array(
                'taxonomy' => 'starts-with',
                'field' => 'slug',
                'terms' => $startwith,
            ),
            array(
                'taxonomy' => $field3,
                'field' => 'slug',
                'terms' => $field3vl,
            ),
        );
    }
    // query babyname
    $the_query = new WP_Query($args);
    // doing ajax stuff
    ?>
    <ul class="names-results listing-view" id=":0.nr" style="-webkit-user-select: none;">
        <?php
        while ($the_query->have_posts()) {
            $the_query->the_post();
            ?>
            <?php
            $terms = get_the_terms($post->ID, 'gender');
            $gender = array();
            foreach ($terms as $term) {
                $gender[] = $term->name;
            }
            ?>
            <li <?php
            if ($i == 0) {
                echo 'class="old"';
                $i = 1;
            } else {
                echo 'class="even"';
                $i = 0;
            }
            ?>>
                <a href="<?php the_permalink(); ?>">
                    <?php
                    if ($gender[0] == 'Male') {
                        echo "<span class='result-gender boy'></span>";
                    } elseif ($gender[0] == 'Female') {
                        echo "<span class='result-gender girl'></span>";
                    } else {
                        echo "<span class='result-gender boygirl'></span>";
                    }
                    ?>
                    <span class="result-name"><?php echo get_the_title(); ?></span>
                    <span class="result-desc"></span>
                </a>
            </li>
            <?php
        }
        ?>
    </ul>
    <section class = "pagination">
        <?php emm_paginate(); ?>  
    </section>
    <?php
    die(); // stop executing script
}

add_action('wp_ajax_ajax_action', 'ajax_action_stuff'); // ajax for logged in users
add_action('wp_ajax_nopriv_ajax_action', 'ajax_action_stuff'); // ajax for not logged in users
?>
功能查询_主页(){
wp_enqueue_script('ajax-script',get_stylesheet_directory_uri()。/library/js/ajax query.js',array('jquery'),1.0);//jquery将自动包含
wp_localize_script('ajax-script','ajax_object',array('ajaxurl'=>admin_url('admin-ajax.php'));//设置ajaxurl
}
添加_操作('init','query_homepage');
函数ajax\u action\u stuff(){
//从ajaxpost获取变量
$startwith=$_POST['startwith'];
$male=$_POST['male'];
$female=$_POST['female'];
$field3=$_POST['field3'];
$field3vl=$_POST['field3vl'];
$page=$_POST['page'];
如果($male!=”“&&$female!=”“){
$SEXT=数组(“两个名称”、$FEMER、$male);
}elseif($male!=“”){
$性别=$男性;
}elseif($female!=“”){
$性别=$女性;
}
$args=数组(
“post_type”=>“baby_name”,
“每页帖子数”=>10,
“paged'=>$page,
'orderby'=>'title',
“订单”=>“ASC”,
);
如果($startwith=''&&$field3=''){
$args['tax_query'][]=数组(
排列(
“分类法”=>“性别”,
'字段'=>'段塞',
“术语”=>$SEXT,
),
);
}elseif($startwith==''){
$args['tax_query'][]=数组(
'关系'=>'和',
排列(
“分类法”=>“性别”,
'字段'=>'段塞',
“术语”=>$SEXT,
),
排列(
“分类法”=>$field3,
'字段'=>'段塞',
“条款”=>$field3vl,
),
);
}elseif($field3==''){
$args['tax_query'][]=数组(
'关系'=>'和',
排列(
“分类法”=>“性别”,
'字段'=>'段塞',
“术语”=>$SEXT,
),
排列(
“分类法”=>“以”,
'字段'=>'段塞',
“条款”=>$startwith,
),
);
}否则{
$args['tax_query'][]=数组(
'关系'=>'和',
排列(
“分类法”=>“性别”,
'字段'=>'段塞',
“术语”=>$SEXT,
),
排列(
“分类法”=>“以”,
'字段'=>'段塞',
“条款”=>$startwith,
),
排列(
“分类法”=>$field3,
'字段'=>'段塞',
“条款”=>$field3vl,
),
);
}
//查询babyname
$thew_query=newwp_query($args);
//做ajax的事情
?>
我不知道哪里出错了。我会尽我所能,但不会成功。请帮助我。
抱歉,因为我的英语很差。

我使用brew主主题。我的网站:我使用brew主主题。我的网站:
function query_homepage() {
    wp_enqueue_script('ajax-script', get_stylesheet_directory_uri() . '/library/js/ajax-query.js', array('jquery'), 1.0); // jQuery will be included automatically
    wp_localize_script('ajax-script', 'ajax_object', array('ajaxurl' => admin_url('admin-ajax.php'))); // setting ajaxurl
}

add_action('init', 'query_homepage');

function ajax_action_stuff() {
    // getting variables from ajax post
    $startwith = $_POST['startwith'];
    $male = $_POST['male'];
    $female = $_POST['female'];
    $field3 = $_POST['field3'];
    $field3vl = $_POST['field3vl'];
    $page = $_POST['page'];
    if ($male != "" && $female != "") {
        $gender = array("both-names", $female, $male);
    } elseif ($male != "") {
        $gender = $male;
    } elseif ($female != "") {
        $gender = $female;
    }
    $args = array(
        'post_type' => 'baby_name',
        'posts_per_page' => 10,
        'paged' => $page,
        'orderby' => 'title',
        'order' => 'ASC',
    );
    if ($startwith == '' && $field3 == '') {
        $args['tax_query'][] = array(
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
        );
    } elseif ($startwith == '') {
        $args['tax_query'][] = array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
            array(
                'taxonomy' => $field3,
                'field' => 'slug',
                'terms' => $field3vl,
            ),
        );
    } elseif ($field3 == '') {
        $args['tax_query'][] = array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
            array(
                'taxonomy' => 'starts-with',
                'field' => 'slug',
                'terms' => $startwith,
            ),
        );
    } else {
        $args['tax_query'][] = array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'gender',
                'field' => 'slug',
                'terms' => $gender,
            ),
            array(
                'taxonomy' => 'starts-with',
                'field' => 'slug',
                'terms' => $startwith,
            ),
            array(
                'taxonomy' => $field3,
                'field' => 'slug',
                'terms' => $field3vl,
            ),
        );
    }
    // query babyname
    $the_query = new WP_Query($args);
    // doing ajax stuff
    ?>
    <ul class="names-results listing-view" id=":0.nr" style="-webkit-user-select: none;">
        <?php
        while ($the_query->have_posts()) {
            $the_query->the_post();
            ?>
            <?php
            $terms = get_the_terms($post->ID, 'gender');
            $gender = array();
            foreach ($terms as $term) {
                $gender[] = $term->name;
            }
            ?>
            <li <?php
            if ($i == 0) {
                echo 'class="old"';
                $i = 1;
            } else {
                echo 'class="even"';
                $i = 0;
            }
            ?>>
                <a href="<?php the_permalink(); ?>">
                    <?php
                    if ($gender[0] == 'Male') {
                        echo "<span class='result-gender boy'></span>";
                    } elseif ($gender[0] == 'Female') {
                        echo "<span class='result-gender girl'></span>";
                    } else {
                        echo "<span class='result-gender boygirl'></span>";
                    }
                    ?>
                    <span class="result-name"><?php echo get_the_title(); ?></span>
                    <span class="result-desc"></span>
                </a>
            </li>
            <?php
        }
        ?>
    </ul>
    <section class = "pagination">
        <?php emm_paginate(); ?>  
    </section>
    <?php
    die(); // stop executing script
}

add_action('wp_ajax_ajax_action', 'ajax_action_stuff'); // ajax for logged in users
add_action('wp_ajax_nopriv_ajax_action', 'ajax_action_stuff'); // ajax for not logged in users
?>