September 19, 2016

How to show a list of all available categories on one page.

Here’s a neat little thing. I had all the categories of a custom post type on the page floating around dynamically like a tag cloud as an animated design element. It made the processor choke like a horror show, but the overall effect was cool. Note to self. Figure out how to put this into canvas.

[pastacode lang=”php” manual=”%20%20%20%20%3C%3Fphp%20%0A%20%20%20%20%24args%20%3D%20array%20(%0A%20%20%20%20%20%20%20%20’taxonomy’%20%3D%3E%20’employee-type’%2C%20%2F%2Fyour%20custom%20post%20type%0A%20%20%20%20%20%20%20%20’orderby’%20%3D%3E%20’name’%2C%0A%20%20%20%20%20%20%20%20’order’%20%3D%3E%20’ASC’%2C%0A%20%20%20%20%20%20%20%20’hide_empty’%20%3D%3E%200%20%2F%2Fshows%20empty%20categories%0A%20%20%20%20)%3B%0A%20%20%20%20%24categories%20%3D%20get_categories(%20%24args%20)%3B%0A%20%20%20%20echo%20’%3Cul%20class%3D%22floating-cats%20one%22%3E’%3B%0A%20%20%20%20foreach%20(%24categories%20as%20%24category)%20%7B%20%20%20%20%0A%20%20%20%20%20%20%20%20%24post_by_cat%20%3D%20get_posts(array(‘cat’%20%3D%3E%20%24category-%3Eterm_id))%3B%0A%20%20%20%20%20%20%20%20echo%20’%3Cli%3E’%20.%20%24category-%3Ename%20.%20’%3C%2Fli%3E’%3B%0A%20%20%20%20%7D%3B%0A%20%20%20%20echo%20’%3C%2Ful%3E’%3B%0A%20%20%20%20%3F%3E%0A” message=”List All Categories of Custom Post Type” highlight=”” provider=”manual”/]