Display WordPress Pages or Categories in 2-3 Columns

If you have a lot of pages or categories on your site and you would like to break them out into columns when displaying them via WordPress’ wp_list_pages or wp_list_categories function this article will show you to do just that. Simply put what we are going to do is use some PHP to place all the unordered list elements into an array and then some simple division to break the array into separate variables that we can in turn echo out into our columns. We will then use CSS to make our columns once the pages are in place.

WP_List_Page: Display Output in Multiple Columns

Let’s use a bit of math and some PHP to get our pages, place the list into an array and then divide it up to suit our multi-column needs. The code below should be used within the WordPress loop

Two Columns

The WordPress function WP_List_Pages is great for outputting an dynamic list of your pages that can be easily styled. Let’s expand upon this function with some PHP to display some columns.

Three Columns

The difference with the code below from the bit above is that we are going to be breaking up our array into three separate unordered lists so that they can be styled with CSS. Like before, ensure you change the arguments for the wp_List_pages function to suit your needs.

WP_List_Categories: Display Output in Columns

Most likely, you have a lot of categories and want to display them in a bit nicer fashion than a long list that pushes the page length down off the screen. This is an excellent idea and your users will thank you. Most likely, you are using the

Two Columns

Three Columns

Extra Info that May Help You

The great thing about WordPress is that there’s a ton of plugins that can make your life much easier. If you are looking to display your tags in multiple columns you may want to have a look at: Multi-column Tag Map. This plugin is pretty cool in that it display your tags in columns and also have a nice optional show/hide jQuery toggle effect. I also got this plugin to work with Categories and it works really well for those as well.

Wrapping Up: What We Learned

We see that our WordPress functions wp_list_pages and wp_list_categories can be used with some PHP to create any number of columns. If you need more than three columns, simple tweak the math and you’ll have the number of columns you want in no time. Still having trouble? Please use the comments below and we’ll set you straight!

Devin Walker is a San Diego-based WordPress Developer and enthusiast. He is the author of several popular and highly-rated WordPress themes and plugins. In his free time he enjoys playing Golf and traveling.

Follow Devin: