您可以为每个表标题定义一个简单的锚定标记,具有自己的单独id,然后您必须为每个标题使用onclick事件,这取决于发送ajaxrequest的id,以获得按相应顺序排序的结果。使用相应的结果,可以用最新的结果替换父div的内容。
要实现这一点,您应该了解wordpress中的管理Ajax。
Admin Ajax: 在标题中。php
<script type="text/javascript">
var ajax_url = \'<?php echo admin_url(\'admin-ajax.php\'); ?>\';
</script>
in your html add same class to all th and add a diff id to to each one of them, make the respective changes in js
in you custom js file like "my-custom.js", enqueue the js file , replace the class th-class with corresponding class in your html as well as js:
jQuery(document).ready(function(){
jQuery(body).on(\'click\',\'th-class\', function(){
var column_id = jQuery(this).attr(\'id\');
jQuery.ajax({
type: "POST",
url: "ajax_url",
data: {
action: \'reorder_table\',
column_id: column_id,
},
success: function(res){
console.log(res);
//append the result in frontend
},
})
})
});
在您的功能中。php
function sort_table_data(){
//get your results here as per column id
if(!empty($_POST[\'column_id\'])){
$column_id = $_POST[\'column_id\'];
$output = \'\';
//rest of the code as per column id, store result in $output
echo $output;//you result here
die(1);
}
}
add_action(\'wp_ajax_reorder_table\', \'sort_table_data\');
add_action(\'wp_ajax_no_priv_reorder_table\', \'sort_table_data\');
**我已经添加了我可以很快得到的代码,因此您可能需要修复错误,但这就是您的过程将如何进行。您可以参考
http://wp.tutsplus.com/articles/getting-started-with-ajax-wordpress-pagination/ 也