📅  最后修改于: 2022-03-11 14:53:40.224000             🧑  作者: Mango
// Register our tweaked Category Archives widget
function myprefix_widgets_init() {
register_widget( 'WP_Widget_Categories_custom' );
}
add_action( 'widgets_init', 'myprefix_widgets_init' );
/**
* Duplicated and tweaked WP core Categories widget class
*/
class WP_Widget_Categories_Custom extends WP_Widget {
function __construct()
{
$widget_ops = array( 'classname' => 'widget_categories widget_categories_custom', 'description' => __( "A list of categories, with slightly tweaked output.", 'mytextdomain' ) );
parent::__construct( 'categories_custom', __( 'Categories Custom', 'mytextdomain' ), $widget_ops );
}
function widget( $args, $instance )
{
extract( $args );
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories Custom', 'mytextdomain' ) : $instance['title'], $instance, $this->id_base);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
?>
]*)>]*)>(.*?)<\/a>\s*\(([0-9]*)\)\s*<\/li>#i'; // removed ( and )
// $replacement = '- $3$4'; // no link on span
// $replacement = '
- $3$4'; // wrap link in span
$replacement = '
- $3 ($4)'; // give cat name and count a span, wrap it all in a link
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 1,
'title_li' => '',
'exclude' => '2,5,31',
'echo' => 0,
'depth' => 1,
);
$subject = wp_list_categories( $args );
echo preg_replace( $pattern, $replacement, $subject );
?>
'') );
$title = esc_attr( $instance['title'] );
$count = true;
$hierarchical = false;
$dropdown = false;
?>
disabled="disabled" />