Problem Description:

On the main page for your Portfolio, or themes with an Album, Gallery or similar custom post type, the category links will sort themselves based on the number of posts in each, with the largest count first. This can be changed by editing the template. The following provides an example of how to do this in a standard portfolio category template.

Please note that not all themes use the same category query so the code may vary.

Answer:

This is considered a modification, and is provided as-is. We expect you understand what you are doing if applying coding changes using these or other WordPress tutorials. Make a backup of your existing file so you can replace it if something goes wrong and you need to start over. Modified files WILL probably be replaced by a theme update at some point, so keep note of your changes for future reference or see our guides below. We cannot assist you with modifying your theme or support problems you encounter as a result!

If you are modifying a theme as part of a client project, the following are really important!

How to Modify Your Theme the Right Way
How to Track Update Changes and Maintain Modifications

eCommerce Themes (Store, Retail Therapy, Dynamo, etc)

 

  1. Go to Appearance  → Editor and click on taxonomy-portfolio-category.php
  2. Line 4 will show the following
    	$terms = get_terms("portfolio-category", "orderby=count&hide_empty=0&parent=0");
  3. Change count to your desired value. Your choices are:
    • ID – the order you created the categories
    • name – alphabetical
  4. Click Update File when done
  5. Repeat for portfolio.php

$terms = get_terms(“portfolio-category”, “orderby=name&hide_empty=0&parent=0”);

If your categories are displaying in the wrong direction, (ie Z to A), add an order parameter. Example

  • ASC‘ – ascending order from lowest to highest values (1, 2, 3; a, b, c).
  • DESC‘ – descending order from highest to lowest values (3, 2, 1; c, b, a).
$terms = get_terms("portfolio-category", "orderby=name&order=ASC&hide_empty=0&parent=0");

Each argument must be separated by an ampersand (&)

 

Older themes: Knead, Gigawatt, Handmade, Personal, Principles

  1. Go to Appearance  → Editor and click on taxonomy_portfolio-category.php
  2. Find the following near the top:
    	cat_list = get_terms("portfolio-category", "orderby=count&hide_empty=0");
  3. Change count to your desired value. Your choices are:
    • ID – the order you created the categories
    • name – alphabetical
  4. Click Update File when done
  5. Repeat for portfolio.php

See the WordPress Codex for details on how to use orderby and order

Example:

$term = get_term_by( 'slug', get_query_var('term' ), get_query_var( 'taxonomy' ) ); $cat_list = get_terms("portfolio-category", "orderby=name&hide_empty=0");