2016-09-12 1 views
0

에 다음 페이지를로드 :워드 프레스 내가 워드 프레스에서이 페이지를 구현하려면 마우스 휠

<div id="content"> 
      <h1>Main Area</h1> 
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
       <h1><?php the_title(); ?></h1> 
       <h4>Posted on <?php the_time('F jS, Y') ?></h4> 
       <p><?php the_content(__('(more...)')); ?></p> 
       <hr> <?php endwhile; else: ?> 
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?> 
     </div> 

내 질문은 어떻게 이벤트를 통해 다음 게시물을로드 할 수 있습니까? 로드 된 게시물.

+0

이것은 아마 ajax를 포함 할 것입니다. – developerwjk

답변

0

이미 중간에 있습니다. 다음으로해야 할 일은 아약스 요청을 작성하고 PHP 콜백을 사용하여 다음 페이지를로드하는 것입니다. 코드는 다음과 같습니다. 주석에 특별한주의를 기울이십시오.

jQuery를

$.ajax({ 
    url: data.ajax_url, // Localize this variable using Wordpress functions 
    type: 'post', 
    data: { 
     action: 'load_nextpage_page', // The name of php callback (function) 
     // Any other variables you may wish to pass 
    }, 
    success: function(data) { 
     console.log(data); 
     // Here you can use the data returned by you PHP callback 
    } 
}); 

PHP

내가이 일을 구축해야 할 수도 있습니다 모든 것을 설명했다
<?php 

// your-javascript-file-handle is the one you use while enqueuing your JS files in wordpress. Use the same handle in following code 
// to know more about localization visit https://developer.wordpress.org/reference/functions/wp_localize_script/ 

wp_localize_script('your-javascript-file-handle', 'data', array(
    'ajax_url' => admin_url('admin-ajax.php'), 
)); 


// AJAX callback handling 
add_action('wp_ajax_load_nextpage_page', 'load_nextpage_page'); 
add_action('wp_ajax_nopriv_load_nextpage_page', 'load_nextpage_page'); 

function load_nextpage_page() 
{ 
    // Code for fetching next post here 
    // Remember you will need a variable to keep track of which post should be fetched next. 


    // Once you have fetched the right post 
    // you can echo the contents which will be passed as a reposnse to your ajax request. 
} 

. 나는 그것이 당신을 돕기를 바랍니다.