Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.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 如何在wordpress中添加这个无限代码?_Php_Database_Mysqli_Wordpress - Fatal编程技术网

Php 如何在wordpress中添加这个无限代码?

Php 如何在wordpress中添加这个无限代码?,php,database,mysqli,wordpress,Php,Database,Mysqli,Wordpress,我想在我的WordPress网站上使用滚动无限循环。我在一些网站上发现了以下代码,它在静态PHP页面上非常有效。但是现在我想在我的WordPress博客中添加这个功能,但我不知道如何 index.php 请帮我弄清楚怎么做 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"

我想在我的WordPress网站上使用滚动无限循环。我在一些网站上发现了以下代码,它在静态PHP页面上非常有效。但是现在我想在我的WordPress博客中添加这个功能,但我不知道如何

index.php

请帮我弄清楚怎么做

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto Loading Records</title>
<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>

<?php
include("config.php");
$results = $mysqli->query("SELECT COUNT(*) as t_records FROM paginate");
$total_records = $results->fetch_object();
$total_groups = ceil($total_records->t_records/$items_per_group);
$results->close(); 
?>

<script type="text/javascript">
$(document).ready(function() {
    var track_load = 0; //total loaded record group(s)
    var loading  = false; //to prevents multipal ajax loads
    var total_groups = <?php echo $total_groups; ?>; //total record group(s)
    
    $('#results').load("autoload_process.php", {'group_no':track_load}, function() {track_load++;}); //load first group
    
    $(window).scroll(function() { //detect page scroll
        
         if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
            
            if(track_load < total_groups && loading==false) //there's more data to load
            {
                loading = true; //prevent further ajax loading
                $('.animation_image').show(); //show loading image
                
                //load data from the server using a HTTP POST request
                $.post('autoload_process.php',{'group_no': track_load}, function(data){
                                    
                    $("#results").append(data); //append received data into the element

                    //hide loading image
                    $('.animation_image').hide(); //hide loading image once data is received
                    
                    track_load++; //loaded group increment
                    loading = false; 
                
                }).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
                    
                    alert(thrownError); //alert with HTTP error
                    $('.animation_image').hide(); //hide loading image
                    loading = false;
                
                });
                
            }
        }
    });
});
</script>

</head>

<body>

<ol id="results">
</ol>
<div class="animation_image" align="center"><img src="ajax-loader.gif"></div>


</body>
</html>
<?php
include("config.php"); //include config file

if($_POST)
{
    //sanitize post value
    $group_number = filter_var($_POST["group_no"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
    
    //throw HTTP error if group number is not valid
    if(!is_numeric($group_number)){
        header('HTTP/1.1 500 Invalid number!');
        exit();
    }
    
    //get current starting point of records
    $position = ($group_number * $items_per_group);
    
    //Limit our results within a specified range. 
    $results = $mysqli->query("SELECT id,name,message FROM paginate ORDER BY id ASC LIMIT $position, $items_per_group");
    
    if ($results) { 
        //output results from database
        
        while($obj = $results->fetch_object())
        {
            echo '<li id="item_'.$obj->id.'">'.$obj->id.' - <strong>'.$obj->name.'</strong></span> &mdash; <span class="page_message">'.$obj->message.'</span></li>';
        }
    
    }
    unset($obj);
    $mysqli->close();
}
?>
object(stdClass)[3661]

  public 't_records' => string '1257' (length=4)