簡體   English   中英

wordpress .post()500服務器錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM