php - Wordpress load next page on mousewheel -
i want implement page in wordpress: http://www.spendeeapp.com/
basically, loading next post on mousescroll functionality
i can replicate mousescroll action thru jquery
$(document).ready(function(){ $(document) .on('mousewheel dommousescroll swipedown swipeup', function(){ // }) });
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 criteria.'); ?></p><?php endif; ?> </div>
my question is, how can load next post thru event, , display loaded post.
you halfway there. need next create ajax request , load next page using php callback. code this. pay special attention comments.
jquery
$.ajax({ url: data.ajax_url, // localize variable using wordpress functions type: 'post', data: { action: 'load_nextpage_page', // name of php callback (function) // other variables may wish pass }, success: function(data) { console.log(data); // here can use data returned php callback } });
php
<?php // your-javascript-file-handle 1 use while enqueuing js files in wordpress. use same handle in following code // know more 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 fetching next post here // remember need variable keep track of post should fetched next. // once have fetched right post // can echo contents passed reposnse ajax request. }
i have outlined might need build thing. hope helps you.
Comments
Post a Comment