Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress widget categories edit

// 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;
        ?>
        <ul>
            <?php
            // Get the category list, and tweak the output of the markup.
            $pattern = '#<li([^>]*)><a([^>]*)>(.*?)</a>s*(([0-9]*))s*</li>#i';  // removed ( and )

            // $replacement = '<li$1><a$2>$3</a><span class="cat-count">$4</span>'; // no link on span
            // $replacement = '<li$1><a$2>$3</a><span class="cat-count"><a$2>$4</a></span>'; // wrap link in span
            $replacement = '<li$1><a$2><span class="cat-name">$3</span> <span class="cat-count">($4)</span></a>'; // 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 );
            ?>
        </ul>
        <?php
        echo $after_widget;
    }

    function update( $new_instance, $old_instance )
    {
        $instance = $old_instance;
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['count'] = 1;
        $instance['hierarchical'] = 0;
        $instance['dropdown'] = 0;

        return $instance;
    }

    function form( $instance )
    {
        //Defaults
        $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
        $title = esc_attr( $instance['title'] );
        $count = true;
        $hierarchical = false;
        $dropdown = false;
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('title', 'mytextdomain' ); ?>"><?php _e( 'Title:', 'mytextdomain'  ); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
        </p>
        <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" <?php checked( $count ); ?> disabled="disabled" />
        <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts', 'mytextdomain'  ); ?></label>
        <br />
        <?php
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: how-to-customize-the-email-verification-email-from-laravel-8 
Php :: call stored procedure in laravel 
Php :: do php 
Php :: php domdocument get elements one by one 
Php :: php ffi get load average 
Php :: repalce 0 in phone with 234 
Php :: php thorwable vs exception 
Php :: shorthand to assign multiple variable to same value in php 
Php :: lewin muzvonda 
Php :: Uncaught TypeError: call_user_func(): Argument #1 
Php :: php-like-system-with-notification-using-ajax-jquery 
Php :: laravel how to read app/config/app.php debug variable 
Php :: woocommerce show percentage in sales badge 
Php :: how to put external file in laravel listener class 
Php :: if gd is image 
Php :: Laravel advanced sub queries 
Php :: php formula return more results 
Php :: mac php.ini catalina 
Php :: laravel compile blade 
Php :: Detecting specifically the My account "Dashboard" page 
Php :: preg_replace rules for php 7.3 
Php :: laavel relation through morph 
Php :: jupiter/framework/admin/generators/option-generator.php on line 80 
Php :: sage theme get template 
Php :: php check timeout 
Php :: test lockForUpdate laravel 
Php :: has_post_format wordpress 
Php :: eager loading in hasmany belongsto relationship 
Php :: Compare current time with another time in PHP 
Php :: tutorial crud phpmyadmin 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =