• I have created taxonomies by the names Company, Country and City.
    Now I want to display it on the index page like that:

    Listed companies: HP, IBM, Apple …
    Listed countries: USA, Sweden, Canada …
    Listed cities: NY, Stockholm, Toronto …

    The first 3 tags are supposed to be the most popular in each taxonomy.
    I guess it can be done only by hard coding into the theme, but how can I do it?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You should be able to use the get_terms() function.

    It would go something like this (UNTESTED):

    <?php $companies = get_terms('Company','orderby=count&order=DESC&fields=names');
    if ($companies) {
       echo '<p>Listed companies: ';
       $sep = '';
       foreach ($companies as $company) {
          echo $sep . $company;
          $sep = ', ';
       }
       echo '</p>';
    }?>
    Thread Starter omerosen

    (@omerosen)

    the code works great except for that it doesn’t link the tags, only showing them as a text.
    Also, is there a way to limit the nu,ber of shown tags, for example to the most popular 5?

    AFAIK, there is no way to create permalinks for custom taxonomies without a plugin – therefore, no links.

    As for limiting the number, add the number parameter:

    <?php $companies = get_terms('Company','orderby=count&order=DESC&fields=names&number=5');
    if ($companies) {
       echo '<p>Listed companies: ';
       $sep = '';
       foreach ($companies as $company) {
          echo $sep . $company;
          $sep = ', ';
       }
       echo '</p>';
    }?>
    Thread Starter omerosen

    (@omerosen)

    Great, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying taxonomies’ is closed to new replies.