Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Example given by mototribe
How to show countryicons with the user info - 7.x:
Use http://drupal.org/project/countries module and add a country field to the user entity.
A. Using a view:
Create a view to show users, add the user country field to the view and select fomatter "country icon image shiny". This will show the country flag.
B. Modifying the theme:
To show user flags with comments modify template.php of your theme (Bartik in this example):
function bartik_preprocess_comment(&$variables) {
$comment = $variables['comment'];
// Full load user
$user = user_load($comment->uid);
// Now access your field
$country = field_get_items('user', $user, 'field_country');
// krumo($country);
if ($country) {
$variables['user_country_name'] = $country[0]['safe'];
$variables['user_country_flag'] = theme('countryicons_icon', array('code' => $country[0]['iso2'], 'iconset' => 'shiny'));
}
else {
$variables['user_country_name'] = '';
$variables['user_country_flag'] = '';
}
}
add the 2 variables to your comment.tpl.php
<?php print $user_country_flag; ?>
<p class="comment-time">
<?php print $user_country_name; ?>
</p>