hi,

I have a free-tagged taxonomy vocabulary called 'cities', taxonomy-id = '41'. Each user inputs one value.

How can I later display the city for the current user? Basicly I need to print that value this city value holds for the current user.

What should go between these tags?

<?php
print
?>

Comments

nevets’s picture

Need another piece of information, how/where does the user input this value? In general the answer is

<?php
global $user;

// Look up the users city
// Depends on how it is stored

print $the_users_city;
?>
nancydru’s picture

Unfortunately for you, the taxonomy table (term_data) does not store the userid of the person who created it. Is there a reason why you do it this way rather than adding a City field to their profile?

The only thing I can think of is to locate a node they created with this vocabulary and extract the term from that angle.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

Island Usurper’s picture

Also, how do you prevent the users from putting more than one city in the taxonomy field?

Taxonomy's really for categorizing nodes, not users. Maybe you could do something with a user-node module, but I think there are better solutions. Profile, or something like it seems like the best bet.

-----
Übercart -- One cart to rule them all.

vjuhasz’s picture

Thank you for all the responses, very kind of you.

What I did:

1. Created a user profile with CCK, one of the fields is the city ['field_city'], based on a text field. The user profile is based on this tutorial http://www.shellmultimedia.com/node/5

2. I got the city displayed here like this

<div class="panel-2col-stacked"  id='user-profile'>
  
  <!-- TOP PANEL -->
  <div class="panel-col-top">
    
    <!-- Print the user's avatar -->    
    <div id="user-basics">

    <?php print theme('user_picture', $profileuser); ?>
    <table>
      <tr>
      
        <td>
        <?php 
        if (empty($node->content['field_city']['#value'])) {
          print "<strong>City: </strong><i>Not given</i>";
        } else {
          print $node->content['field_city']['#value'] ;
        }
        ?>
        </td>

etc.

As you can see it prints the [field_city] CCK text variable. This works well.

However I thought I could use a freetaged taxanomy category instead of the plain text field, and this would build me up a city database. Now I would like to modify the above code by printing the freetagged taxanomy value instead of the text field. (tid = 41)

nevets’s picture

Instead of '#value' try '#view'. If that does not work add

<pre>
<?php print_r($node->content, TRUE); ?>
</pre>

to see the parts of $node->content.

vjuhasz’s picture

If I switch from the text field to a free-tagged category, the [field_city] will not exist anymore.

I need to extract the data form the city category of the user profile.

nevets’s picture

The taxonomy terms are stored as an arrray in $node->taxonomy so you will want something like

<?php
$vid = 41;
foreach ( $node->taxonomy as $term ) {
  if ( $term->vid == $vid ) {
    // We want to do something with this term
    // $term->tid is the term id
    // $term->name is the "value" (city in your case) of the term
  }
}
?>