我刚刚为我的wordpress博客创建了无限循环,它在我的本地PC(WAMP)上工作得很好,但是当我把它放在网上(nginx服务器)时它显示POST http://www.siteurl.com/infinite-loop.php 500 Internal Server Error
Infinite_loop.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 IN THEME HEADER
<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上运行良好但在线服务器上显示错误。任何人都可以请帮助我知道问题是什么?请帮忙......
答案 0 :(得分:0)
要获得最佳WordPress实践,您应该使用WordPress的ajax functions。把它放在你的主题functions.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>
答案 1 :(得分:0)
我得到了解决方案...... 它是一个wordpress问题 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();