我刚刚为我的wordpress博客创建了无限循环,它在我的本地PC(WAMP)上运行得很好,但当我把它放到网上(nginx服务器)时,它显示POST http://www.siteurl.com/infinite-loop.php 500 Internal Server Error
Infinite_roop.php
<?php
$infinite_loop= $_POST['pcount']; ?>
<?php require_once("/wp-blog-header.php"); ?>
<div class="x-container-fluid max width main">
<div class="offset cf">
<div class="<?php x_main_content_class(); ?>" role="main">
<?php
global $wpdb;
$args = array( 'posts_per_page' => 10, 'order' => 'DESC', 'offset'=>$infinite_loop );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div>
<div style="width:300px; float:left;">
<?php x_ethos_featured_index(); ?>
</div>
<div style="width:500px; float:right;">
<?php /* print $args['offset']; */ ?>
<?php x_get_view( 'ethos', '_content', 'post-header' ); ?>
<?php x_get_view( 'global', '_content' ); ?>
<?php
</div>
</div>
</article>
<?php endforeach;
wp_reset_postdata(); ?>
</div> <?php get_sidebar(); ?>
</div></div>
主题标题中的AJAX
<script>
$(document).ready(function() {
var post_page_count = 10;
var height_scroll = 400;
$(window).scroll(function() {
if ($('body').height() <= ($(window).height() + $(window).scrollTop())){
post_page_count = post_page_count+10;
$.ajax({
type: "POST",
async: false,
url: "theme/infinite_loop.php",
data: {pcount:post_page_count},
success:
function(result){
$("#gizinfi").append(result);
}
});
};
});
});
</script>
我不知道问题出在哪里。它在带有WAMP的本地PC上运行得很好,但在在线服务器上显示错误。有人能帮我知道问题出在哪里吗?请帮忙。。。
为了获得最佳的WordPress实践,您应该使用WordPress的ajax功能。将其放在您的主题函数.php文件中
<?php
add_action( 'wp_ajax_my_inifinte_loop', 'my_inifinte_loop' );
add_action( 'wp_ajax_my_inifinte_loop', 'my_inifinte_loop' );
function my_inifinte_loop() {
$infinite_loop= $_POST['pcount'];
?>
<div class="x-container-fluid max width main">
<div class="offset cf">
<div class="<?php x_main_content_class(); ?>" role="main">
<?php
global $wpdb;
$args = array( 'posts_per_page' => 10, 'order' => 'DESC', 'offset'=>$infinite_loop );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div>
<div style="width:300px; float:left;">
<?php x_ethos_featured_index(); ?>
</div>
<div style="width:500px; float:right;">
<?php /* print $args['offset']; */ ?>
<?php x_get_view( 'ethos', '_content', 'post-header' ); ?>
<?php x_get_view( 'global', '_content' ); ?>
<?php
</div>
</div>
</article>
<?php endforeach;
wp_reset_postdata(); ?>
</div> <?php get_sidebar(); ?>
</div>
</div>
<?php
die();
}
?>
然后将您的javascript更新为
<script>
$(document).ready(function() {
var post_page_count = 10;
var height_scroll = 400;
$(window).scroll(function() {
if ($('body').height() <= ($(window).height() + $(window).scrollTop())){
post_page_count = post_page_count+10;
$.ajax({
type: "POST",
async: false,
url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
data: {
pcount:post_page_count,
action: 'my_inifinte_loop'
},
success:
function(result){
$("#gizinfi").append(result);
}
});
};
});
});
</script>
我得到了解决方案。。。这是一个文字新闻问题Wordpress头被设置为允许外部插件风格的开发。我包含的标题不正确,这就是为什么我得到404和500错误。
我更改
<?php require_once("/wp-blog-header.php"); ?>
至
require('/wp-config.php');
$wp->init();
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();