Hi,

I am using the below stated code to display the terms associated with the page.Is there any way to show it in ascendng and descending order alphabetically.

/**
* Prints an unordered list of the terms (as links) that are
* associated to the currently displayed node.

if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    $node = node_load(arg(1));
    $vid = 2;
    $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    if ($terms) {
print '<ul>';
                foreach ($terms as $term) {
                print '<li>'.l($term->name, 'taxonomy/term/'.$term->tid).'</li>';

          }
print '</ul>';
    }
}

**/

Current Result:
Mango
Apple
Orange
Bananna

Required Result:
Apple
Bannana
Mango
Orange

Comments

kars-t’s picture

Priority: Critical » Normal
Status: Needs work » Fixed

Hi

please use the Views module to get this running. Makes more sense to get some experience with Views in any case!

donkasok’s picture

Thankyou for your valid input.Hope i will get it done via views

donkasok’s picture

Hi i have tried to play with views.But didnt gave any result i desired. Can you help me to achive this.

kars-t’s picture

Hi donkasok

basically you create a view about a node. Use a contextual filter with the current node id that is in the current URL. A node URL is always "node/123" for views not the alias that you can see in the browser. So you can use this easily with Views.

Than select the taxonomy field. This already should be an unordered list.

Please take a looka this:
http://dev.nodeone.se/node/701

Views is the best contrib module there is. You can do many amazing things with it. So it is a good invest to learn Views!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.