I want to add some custom bullets next to my categories in my Category Widget so I created a new widget and added in my new html and classes so I can change how it all looks. Unfortunately for some reason my widget is adding a link to one of my last categories all over the store pages as well as where it needs to be (in the category list/sidebar). While everything seems to work the empty a tags all over the place are messing up styling of other elements, adding extra space and making things sit off.
Here is my full widget code:
class mdk_wpcat_widget extends WP_Widget {
// Set up the widget name and description.
public function __construct() {
$widget_options = array(
'classname' => 'mdk_wpcat_widget',
'description' => 'Custom MDK Woocommerce Category Widget'
);
parent::__construct( 'mdk_wpcat_widget', 'Woo Cat Widget', $widget_options );
}
// Create the widget output.
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance[ 'title' ] );
// before and after widget arguments are defined by themes
//$blog_title = get_bloginfo( 'name' );
//$tagline = get_bloginfo( 'description' );
echo $args['before_widget'] . $args['before_title'] . $title . $args['after_title'];
// Custom Woo Category Output
$args = array(
'number' => $number,
'orderby' => 'menu_order',
'order' => 'ASC',
'hide_empty' => $hide_empty,
'include' => $ids
);
//Hides "film" category by ID
$args['exclude'] = '72';
$product_categories = get_terms( 'product_cat', $args );
$count = count($product_categories);
if ( $count > 0 ){
echo '<ul class="shop-categories">';
foreach ( $product_categories as $product_category ) {
echo '<li class="shop-category ' . (( $product_category->name == single_cat_title('', false) )?"active-cat":"") . '"><a href="' . get_term_link( $product_category ) . '"><span class="bulletpoint"></span><span class="category-title">' . $product_category->name . '</span></li>';
}
echo '</ul>';
}
echo $args['after_widget'];
}
// Create the admin area widget settings form.
public function form( $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
<input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" />
</p><?php
}
// Apply settings to the widget instance.
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
return $instance;
}
}
// Register the widget.
function mdk_wpcat_load_widget() {
register_widget( 'mdk_wpcat_widget' );
}
add_action( 'widgets_init', 'mdk_wpcat_load_widget' );
I know it is the widget causing the issue because i can remove it from my functions.php file and everything looks right again. I am running the latest version of wp and woocommerce as of 7/5/2017 and i also tried in Twenty Seventeen theme to make sure it was not my current theme.
Thanks for the help!