Files
homeproz/wp-content/themes/homeproz/template-parts/sidebar/blog-sidebar.php
T

85 lines
2.5 KiB
PHP

<?php
/**
* Blog Sidebar Template Part
*
* @package HomeProz
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
?>
<div class="sidebar-widgets">
<!-- Search Widget -->
<div class="sidebar-widget widget-search">
<h3 class="widget-title">Search</h3>
<?php get_search_form(); ?>
</div>
<!-- Categories Widget -->
<?php
$categories = get_categories(array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
'hide_empty' => true,
));
if ($categories) :
?>
<div class="sidebar-widget widget-categories">
<h3 class="widget-title">Categories</h3>
<ul class="category-list">
<?php foreach ($categories as $category) : ?>
<li>
<a href="<?php echo esc_url(get_category_link($category->term_id)); ?>">
<?php echo esc_html($category->name); ?>
<span class="count">(<?php echo esc_html($category->count); ?>)</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<!-- Recent Posts Widget -->
<?php
$recent_posts = new WP_Query(array(
'posts_per_page' => 5,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
));
if ($recent_posts->have_posts()) :
?>
<div class="sidebar-widget widget-recent-posts">
<h3 class="widget-title">Recent Posts</h3>
<ul class="recent-posts-list">
<?php
while ($recent_posts->have_posts()) :
$recent_posts->the_post();
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
<span class="post-date"><?php echo esc_html(get_the_date()); ?></span>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php
wp_reset_postdata();
endif;
?>
<!-- Contact CTA Widget -->
<div class="sidebar-widget widget-cta">
<h3 class="widget-title">Need Help?</h3>
<p>Have questions about buying or selling? We're here to help!</p>
<a href="<?php echo esc_url(home_url('/contact/')); ?>" class="btn btn-primary btn-small">Contact Us</a>
</div>
</div>