This is the widget function -
function widget($args, $instance) {
$hashmap = array(
'arts' => array('avlart', 'avlent'),
'beer' => array('avlbeer'),
'business' => array('avlbiz'),
'craft' => array('avlcraft'),
'environment' => array('avlenv'),
'food' => array('avleat'),
'humor' => array('avllol'),
'literature' => array('avlbook', 'avlread', 'avlwrite'),
'local-government' => array('avlgov'),
'music' => array('avlmusic'),
'news' => array('avlnews'),
'outdoors' => array('avlout'),
'politics-elections' => array('avlpol', 'avlelect'),
'sustainability' => array('avlenv'),
'wellness' => array('avlhealth'),
);
if (is_home()) {
$hashtags = "";
$hashtags_list = "All hashtags";
} else if (is_category()) {
$cat = get_queried_object();
$slug = $cat->slug;
if (isset($hashmap[$slug])) {
$hashtags = implode(",", $hashmap[$slug]);
$hashtags_list = "#". implode(", #", $hashmap[$slug]);
}
}
if (isset($hashtags)) {
extract($args);
echo $before_widget;
echo $before_title . $instance['title'] . $after_title;
echo "<div id='micronews' data-hashtags='". $hashtags ."' data-show='". $instance['show'] ."'><div class='positive'></div></div>\n";
?>
<?= $hashtags_list; ?>
<?php
echo $after_widget;
wp_enqueue_script( 'mx-micronews-script', plugins_url('js/micronews.js', __FILE__), array('jquery'), '1.0', true );
wp_enqueue_script( 'mx-micronews-timeago', plugins_url('js/jquery.timeago.js', __FILE__), array('jquery'), '1.4.1', true );
}
}
}
function mxnr_widgets_init() {
register_widget('mxnr_micronews');
}
add_action('widgets_init', 'mxnr_widgets_init');
?>