evertsemeijn

Topic: How to sort categories client-side?

I like to sort the categories in the template file (and not in the backend). Is there anyone who knows how to do that?

(I don't want to change the order of the categories in the database, but want to have them sorted alphabetical 'client-side').

Member of Jobberbase Development Team - Templates/Usability :: Looking for installation and/or custom design? :: Beautiful Wordpress themes

redjumpsuit

Re: How to sort categories client-side?

hi, why not just create a separate function that orders the category by name instead of the specified category_order?

you can add this function on your /_includes/functions.php

Code:

function get_categories_order_name()
{
    global $db;
    $categories = array();
    $sql = 'SELECT *
                   FROM categories
                   ORDER BY `name` ASC';
    $result = $db->query($sql);
    while ($row = $result->fetch_assoc())
    {
        $categories[] = array('id' => $row['id'], 'name' => $row['name'], 'var_name' => $row['var_name'], 'title' => $row['title'], 'description' => $row['description'], 'keywords' => $row['keywords']);
    }
    return $categories;
}

and use this to extract the categories ordered alphabetically.

will host your job board for you at minimal cost! read more: http://mim.io/acb992

evertsemeijn

Re: How to sort categories client-side?

I'll try to get it to work. Thanks!

Member of Jobberbase Development Team - Templates/Usability :: Looking for installation and/or custom design? :: Beautiful Wordpress themes