Skip to content

Instantly share code, notes, and snippets.

@jpen365
Created November 16, 2016 04:01
Show Gist options
  • Save jpen365/9aaf742a5f521a747bc84abe5b62a55a to your computer and use it in GitHub Desktop.
Save jpen365/9aaf742a5f521a747bc84abe5b62a55a to your computer and use it in GitHub Desktop.
Iterate through all categories and break them into two columns
<?php
foreach( $categories as $category ) {
$cat_count ++;
$category_link = sprintf(
'<li class="list-unstyled"><a href="%1$s" alt="%2$s">%3$s</a></li>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
if ($cat_count % 2 != 0 ) {
$cat_col_one[] = $category_link;
} else {
$cat_col_two[] = $category_link;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment