Displays categories / archives in two columns [WordPress Sidebar]

In most themes of WordPress, categories si archives Blog listed in sidebar.php (Ie side column of the blog). For those who have many archives and categories in blog space in sidebar is considerably reduced and the blog page is very long.  
Here is a solution to list categories and / or the blog archives in sidebar on two columns uniformWithout need of any Plugin. Gender:

wp-2

In WordPress, the code that lists the categories is: . Listing categories in two columns is very simple. Replace in sidebar.php code with:

<?php 
$cats = explode("<br />",wp_list_categories("title_li=&echo=0&depth=1&style=none"));
$cat_n = count($cats) – 1; 
for ($i=0;$i<$cat_n;$i++): 
if ($i<$cat_n/2): 
$cat_left = $cat_left."<li>".$cats[$i]."</li>"; 
elseif ($i>=$cat_n/2): 
$cat_right = $cat_right."<li>".$cats[$i]."</li>"; 
endif; 
endfor; 
?> 
<ul class="left"> 
<?php echo $cat_left;?> 
</ul> 
<ul class="right"> 
<?php echo $cat_right;?>

In CSSthe theme of WordPress (style.css) Add:

.right {float:left; width:110px;} 
.left {float:left; width:110px;}

Dimensions width: 110px may vary depending on the width of your sidebar

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » net Surfing » Displays categories / archives in two columns [WordPress Sidebar]
Leave a Comment