[英]wordpress .post() 500 server error
我仍在学习Wordpress,并且正在使用.post()函数来获取特定帖子ID的内容。 每当我尝试回显ID时,输出都没有问题。 但是当我尝试获取内容时,控制台总是抛出500(内部服务器错误)。
我不知道我在做什么错。
这是我的代码。
<div class="container inner-container"> <div class="col-sm-3 col-md-3 sidebar"> <h4 class="bold"><?php echo $cat_name; ?></h4> <hr> <nav class="side-nav"> <ul> <?php $posts=q uery_posts( array( 'post_type'=>'post', 'posts_per_page' => 5, 'order' => 'desc', 'orderby' => 'post_date', 'category_name' => $cat_slug) ); ?> <?php foreach($posts as $p): ?> <li class="view-content" value="<?php echo $p->ID; ?>"> <?php echo $p->post_title; ?><span class="hover-arrow-right"><i class="fa fa-chevron-right"></i></span> </li> <?php endforeach; ?> </ul> </nav> </div> <div class="col-sm-9 col-md-9"> <div class="inner-content"> </div> </div> </div>
这是jQuery。
jQuery('.view-content').click(function(event) { var content = jQuery(this).val(); event.preventDefault(); jQuery.post('<?php echo get_template_directory_uri(); ?>/content-from-ajax.php', { content_id: content, }, function(res) { jQuery('.inner-content').html(res); }) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
这是我在.post()函数中分配的文件。
<?php $content_id = $_POST['content_id']; echo $content_id; ?>
先感谢您。
对不起,我的英语语法不好。
用这个
$html = '';
$posts= new WP_Query(
array( 'post_type'=>'post',
'posts_per_page' => 5,
'order' => 'desc',
'orderby' => 'post_date',
'category_name' => $cat_slug )
); ?>
<?php while ( $posts->have_posts() ) : $posts->the_post();
$html .= '<li class="view-content" value="'.get_the_ID().'">'
.get_the_title().
'<span class="hover-arrow-right">
<i class="fa fa-chevron-right"></i>
</span>
</li>';
endwhile;
echo $html;
die();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.