<?php
/**
 * The sidebar containing the main widget area.
 *
 * @package Technical Blogging
 */


?>

<aside id="secondary" class="widget-area" role="complementary">
	<?php dynamic_sidebar( 'primary-sidebar' ); ?>
</aside><!-- #secondary -->

<?php if ( ! is_active_sidebar( 'primary-sidebar' ) ) { ?>

	<aside id="secondary" class="widget-area" role="complementary">
		<!-- Search -->
		<aside id="search-3" class="widget widget_search">
			<h2 class="widget-title"><?php esc_html_e('Search Here', 'technical-blogging'); ?></h2>
			<?php get_search_form(); ?>
		</aside>
		<!-- Categories -->
		<aside id="categories" class="widget widget_categories" role="complementary" aria-label="<?php esc_attr_e( 'secondsidebar', 'technical-blogging' ); ?>">
		    <h2 class="widget-title"><?php esc_html_e('Categories', 'technical-blogging'); ?></h2>
		    <ul>
		        <?php
		        $args = array(
		            'title_li' => '',
		        );
		        wp_list_categories($args);
		        ?>
		    </ul>
		</aside>
		<!-- Archive -->
		<aside id="archive" class="widget widget_archive" role="complementary" aria-label="<?php esc_attr_e( 'secondsidebar', 'technical-blogging' ); ?>">
		    <h2 class="widget-title"><?php esc_html_e('Archive List', 'technical-blogging'); ?></h2>
		    <ul>
		        <?php wp_get_archives('type=monthly'); ?>
		    </ul>
		</aside>
		<!-- Tag Sidebar -->
		<aside id="tag-sidebar" class="widget widget_tag_cloud" role="complementary" aria-label="<?php esc_attr_e( 'thirdsidebar', 'technical-blogging' ); ?>">
		    <h2 class="widget-title"><?php esc_html_e('Popular Tags', 'technical-blogging'); ?></h2>
		    <div class="tagcloud">
		        <?php
		        $technical_blogging_tags = get_tags(array(
		            'orderby' => 'count',
		            'order'   => 'DESC',
		            'number'  => 20, // You can change the number of tags displayed
		        ));

		        if ($technical_blogging_tags) {
		            foreach ($technical_blogging_tags as $technical_blogging_tag) {
		                $technical_blogging_tag_link = get_tag_link($technical_blogging_tag->term_id);
		                $technical_blogging_tag_name = $technical_blogging_tag->name;
		                $technical_blogging_tag_count = $technical_blogging_tag->count;
		                echo '<a href="' . esc_url($technical_blogging_tag_link) . '" class="tag-link" title="' . esc_attr($technical_blogging_tag_name) . ' (' . $technical_blogging_tag_count . ' posts)">' . esc_html($technical_blogging_tag_name) . '</a> ';
		            }
		        } else {
		            echo '<p>' . esc_html__('No tags found.', 'technical-blogging') . '</p>';
		        }
		        ?>
		    </div>
		</aside>	
	</aside>

<?php } ?>
