2016-09-12 2 views
0

ich diese Seite in Wordpress implementieren möchten: http://www.spendeeapp.com/
Grundsätzlich das Laden nächsten Beitrag auf mousescroll FunktionalitätWordpress laden nächste Seite auf Mausrad

ich die mousescroll Aktion durch jQuery replizieren kann

$(document).ready(function(){ 
    $(document) 
     .on('mousewheel DOMMouseScroll swipedown swipeup', function(){ 
      // Do something 
     }) 
}); 

PHP :

<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> 

Meine Frage ist, wie kann ich den nächsten Beitrag durch das Ereignis laden und th anzeigen e geladener Beitrag.

+0

Dies wird höchstwahrscheinlich Ajax beinhalten – developerwjk

Antwort

0

Sie sind schon auf halbem Weg. Alles, was Sie als nächstes tun müssen, ist eine Ajax-Anfrage zu erstellen und die nächste Seite mit einem PHP-Callback zu laden. Der Code sieht ungefähr so ​​aus. Achten Sie besonders auf Kommentare.

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. 
} 

ich alles skizziert haben Sie das Ding bauen könnte müssen. Ich hoffe es hilft dir.