Title: Ordering LInks
Last modified: August 18, 2016

---

# Ordering LInks

 *  [jsterne](https://wordpress.org/support/users/jsterne/)
 * (@jsterne)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/)
 * Hi Everyone,
 * Sorry for the long post. It’s a simple problem but hard for me to explain.
 * I’m using a modified version of the WordPress template, on version 1.5. It’s 
   at [http://sterneworks.org/WordPress](http://sterneworks.org/WordPress) . Right
   now, I’m trying to get the links ordered properly in my sidebar. What I want 
   is “basics (category ID #1), les links (#2), les blogs (#3)” in descending order
   below the search box and “categories.” But I get the opposite, which means that
   somewhere there is a bit of code telling it to place the lowest numbered category
   at the bottom and the highest numbered category at the top.
 * In the WordPress interface, I can’t find any place to change the ID # for categories,
   and in the template, I can’t find the place where it says to put link categories
   from highest to lowest.
 * Obviously, the kludge here is to delete all my links, and start over by ordering
   the category I want on top highest, but there must be a way to fix the code, 
   no?
 * Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Mark Jaquith](https://wordpress.org/support/users/markjaquith/)
 * (@markjaquith)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349295)
 * Well, you could go into the database and manually swich IDs 1 and 3. Or, you 
   can use WP functions to manually call in each category one-by-one. This is definitely
   an area of weakness in WP.
 *  [silkjaer](https://wordpress.org/support/users/silkjaer/)
 * (@silkjaer)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349304)
 * I wrote this little snippet for you, havent tested it, but it should work:
 * `<?php $result = $wpdb->get_results("SELECT cat_id,cat_name FROM $wpdb->linkcategories");
   
   foreach ($result as $category) { $catid = $category->cat_id; $catname = $category-
   >cat_name; ?> <li id="linkcat-<?php echo $catid ?>"><h2><?php echo $catname ?
   ></h2> <ul> <?php get_links($catid, '<li>', '</li>', '', FALSE, 'id', FALSE);?
   > </ul>  <?php } ?>
 *  Thread Starter [jsterne](https://wordpress.org/support/users/jsterne/)
 * (@jsterne)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349341)
 * Thanks for the replies.
 *  Mark — I tried messing with the categories in the database but it doesn’t seem
   to help. It’s possible that what’s happening is that because I want the links
   IN the category alphabetized, it’s also alphabetizing categories. Which would
   be unfortunate. What do you mean “manually calling categories one by one”? How
   would I do that?
 * Silkjaer — thanks for the code, which I’m happy to try — but where do I paste
   it in?
 * Best,
    –J
 *  [silkjaer](https://wordpress.org/support/users/silkjaer/)
 * (@silkjaer)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349362)
 * just paste it in sidebar where where it currently grabs the links (<?php get_links_list()?
   > or something like that.. ) – 🙂
 *  [silkjaer](https://wordpress.org/support/users/silkjaer/)
 * (@silkjaer)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349364)
 * Uhm, sorry, if you want to alphabetize the links, you need to paste this instead;
 * `<?php $result = $wpdb->get_results("SELECT cat_id,cat_name FROM $wpdb->linkcategories");
   
   foreach ($result as $category) { $catid = $category->cat_id; $catname = $category-
   >cat_name; ?> <li id="linkcat-<?php echo $catid ?>"><h2><?php echo $catname ?
   ></h2> <ul> <?php get_links($catid, '<li>', '</li>', '', FALSE, 'name', FALSE);?
   > </ul>  <?php } ?>
 *  Thread Starter [jsterne](https://wordpress.org/support/users/jsterne/)
 * (@jsterne)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349463)
 * Hi Silkjaer,
 * Thanks. It appears to work! Eureka!
 * Best,
    –J
 *  [silkjaer](https://wordpress.org/support/users/silkjaer/)
 * (@silkjaer)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349464)
 * No problem

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Ordering LInks’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [silkjaer](https://wordpress.org/support/users/silkjaer/)
 * Last activity: [20 years, 3 months ago](https://wordpress.org/support/topic/ordering-links-2/#post-349464)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
