Displays the categories / archives on two columns [WordPress Sidebar]

Most of them WordPress themes, categories and archives blog are listed in sidebar.php (more precisely the side column of the blog). For those who have many archives or categories in the blog, the free space from sidebar it is considerably reduced and the blog page becomes very long.
Here is a solution to list the blog's categories and/or archives in the sidebar, on two uniform columns, without needing any plugin. Gen:

wp-2

In WordPress, the code that lists the categories is: <?php wp_list_categories(); ?> . Listing the categories on two columns is very simple. replace in sidebar.php the code <?php wp_list_categories(); ?> cu :

<?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 CSSWordPress theme (style.css) add:

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

The dimensions width:110px they can vary depending on the width of your sidebar.

Passionate about technology, I write with pleasure on stealthsetts.com starting with 2006. I have a rich experience in operating systems: Macos, Windows and Linux, but also in programming languages ​​and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, Presashop).

Home Your source of IT tutorials, useful tips and news. Displays the categories / archives on two columns [WordPress Sidebar]
Leave a Comment