这里有一个脚本,您可以将其排入管理面板。它将在类别选项卡中添加一个名为“活动”的新选项卡。无论何时选中复选框,都会将其添加到“活动”选项卡列表中,您也可以单击“活动”选项卡列表中的链接将其删除(取消选中)。
将此添加为外部脚本,
custom-tabs.js
可能:
jQuery( document ).ready( function( $ ) {
/* Ensure that there are category metaboxes */
if( $( \'ul.category-tabs\' ).length ) {
var taxonomies = [ \'category\', \'tag\' ]; /* Taxonomy Slugs ( category and tag are built-in ) */
/* Loop through each category metabox and add a new tab */
$.each( taxonomies, function( key, taxonomy ) {
/* Add a checkbox listener */
/* Whenever a checkbox is checked or unchecked, remove \'Active\' tab list item */
$( \'#taxonomy-\' + taxonomy + \' ul.categorychecklist input[type="checkbox"]\' ).change( function() {
var label = $( this ).parent().text().trim(); /* Grab checkbox label */
var value = $( this ).val(); /* Grab checkbox value */
/* IF it is checked, add it to the \'Active\' tab */
if( $( this ).is( \':checked\' ) ) {
$( \'#\' + taxonomy + \'-active ul\' ).append( \'<li data-val="\' + value + \'"><a href="javascript:void(0);"><span class="dashicons dashicons-no-alt" style="font-size:18px;text-decoration:none;margin-right:4px;"></span>\' + label + \'</a></li>\' );
/* IF it is unchecked, remove it from the \'Active\' tab */
} else {
$( \'#\' + taxonomy + \'-active li[data-val="\' + value +\'"]\' ).remove();
}
} );
/* Add click listener to the newly added \'Active\' tab links */
$( \'div.inside\' ).on( \'click\', \'#\' + taxonomy + \'-active a\', function() {
var value = $( this ).parent().attr( \'data-val\' );
/* Uncheck any values that have the clicked value */
$( this ).parents( \'div.inside\' ).find( \'input[value="\' + value +\'"]\' ).prop( \'checked\', false );
/* Remove \'Active\' tab link */
$( this ).parent().remove();
} );
/* Append an \'Active\' tab */
$( \'#\' + taxonomy + \'-tabs\' ).append( \'<li><a href="#\' + taxonomy + \'-active">Active</a></li>\' );
$parent = $( \'#\' + taxonomy + \'-tabs\' ).parents( \'div.inside\' );
/* Add the \'Active\' tab panel and content - display none */
$parent.find( \'div.tabs-panel:last\' ).before( \'<div id="\' + taxonomy + \'-active" class="tabs-panel" style="display: none;"><ul></ul></div>\' );
/* IF there are any checked values on load, trigger change. */
$parent.find( \'#\' + taxonomy + \'-all input:checked\' ).each( function() {
$( this ).trigger( \'change\' );
} );
} );
}
} );
接下来,我们可以将其排入管理面板:
function load_custom_tabs_scripts() {
wp_enqueue_script( \'custom_tabs\', get_template_directory_uri() . \'/scripts/custom-tabs.js\' );
}
add_action( \'admin_enqueue_scripts\', \'load_custom_tabs_scripts\' );
如果您遇到问题,请告诉我。