起始位置:
- Detecting Bottom of the page一旦你发现自己处于底部,你需要AJAX 请求使用WP AJAX (tutorial) 保存该数据
您可能希望将“read\\u whole\\u post”存储为Posteta值。大致如下:
add_action( \'wp_ajax_read_whole_post\', \'se200479_read_whole_post\' );
add_action( \'wp_ajax_nopriv_read_whole_post\', \'se200479_read_whole_post\' );
function se200479_read_whole_post() {
// Passed through jQueryAjax in the settings.data argument
$post_id = filter_input( INPUT_POST, \'post_id\' );
// Will return the existing count - ie 0
$current_count = absint(get_post_meta( $post_id, \'read_whole_post\', true ));
// increment your count
$current_count++;
// Update the database value
update_post_meta( $post_id, \'read_whole_post\', $current_count );
// Terminate the AJAX request
wp_send_json_success();
}
您还需要考虑在JS中的页面上存储一些内容,比如
updated = true
确保如果有人在页面上下滚动一堆,您不会多次增加您的计数值!