您是否为 wordpress 尝试过这个特定的帮助函数以使其工作?
http://webjawns.com/2009/11/jquery-tablesorter-helper-function-for-wordpress/
/**
* Make all tables with the specified identifier sortable using the jQuery Tablesorter
plugin.
*
* @uses wp_enqueue_script() To enqueue the jQuery Tablesorter script.
*
* @param string $identifier jQuery selector (.sortable, #element_id, table, etc.)
* @param array $args Default is empty string. Array of arguments to pass to
$.tablesorter()
* @return void
*/
function make_table_sortable($identifier, $args = '') {
global $sortable_tables;
if ( in_array($identifier, (array)$sortable_tables) )
return;
wp_enqueue_script('jquery-tablesorter');
$sortable_tables[] = array(
'identifier' => $identifier,
'args' => $args
);
add_action('admin_print_footer_scripts', '_make_table_sortable');
}
function _make_table_sortable() {
global $sortable_tables;
if ( count( (array)$sortable_tables ) <= 0 )
return;
?>
<script type="text/javascript">
<?php
foreach ($sortable_tables as $sortable_table) {
if ( !is_array($sortable_table['args']) ) {
$arguments = '';
} else {
$arguments = '{';
$args_count = sizeof($sortable_table['args']);
$i = 0;
foreach ($sortable_table['args'] as $k => $v) {
$arguments .= $k . ': ' . $v;
if (++$i != $args_count) $arguments .= ', ';
}
$arguments .= '}';
}
?>
$('<?php echo esc_js($sortable_table['identifier']); ?>').tablesorter(<?php
echo esc_js($arguments); ?>);
<?php } ?>
</script>
<?php
}
下面举例说明 make_table_sortable() 函数的用法:
// Sort tables with class 'sortable', first and second columns in ascending
// order with first taking precedence.
make_table_sortable('.sortable', array('sortList' => '[[0,0], [1,0]]'));
// Sort table with ID 'sortable', first column in ascending order. Turn debugging on.
make_table_sortable('#sortable', array('sortList' => '[[1,0]]', 'debug' => 'true'));
也许这将帮助您更好地解决问题。