I'd like comments on my website to look like this:

Up: comment by a male. Down: comment by a female.

Every comment has to be preceded by an image, depending on the gender of the user who wrote the comment. Users can choose Male/Female as their gender when they register, so the icon can't be changed: it's only related to the gender. How can I achieve this?

  • Is it ok for you to use user profile image for this purpose?
    – arpitr
    Commented Oct 5, 2013 at 22:35
  • Yes, I have no intentions to use the profile image for other purposes anyway.
    – Jeroen
    Commented Oct 5, 2013 at 22:37

1 Answer 1


Create a vocab as gender and add two taxonomies to it as male and female. To the gender vocab add image field and while creating the male and female taxonomy term add the respective images.

Now add the term reference file to user entity and keep it as stele list.

In your custom module hook_user_presave and get the value for the taxonomy field.when you know the selected taxonomy you can load the taxonomy to get the image field fid associated with it assign the fid to $user->picture.

Now everywhere image will load as per the gender selected.

  • Let me know if this workflow looks good to you I'll add some snippets which can be helpful
    – arpitr
    Commented Oct 5, 2013 at 22:56
  • I followed your first paragraph: I succesfully created a new Taxonomy with the Terms 'male' and 'female', which have an image. Can you explain your second step a bit, please? I don't fully understand what you mean.
    – Jeroen
    Commented Oct 5, 2013 at 23:00
  • let me check if I can have you on chat
    – arpitr
    Commented Oct 5, 2013 at 23:02
  • 1
    nice solution arpitr, but is it not so that usage of profile picture is a bit redundant here? I mean we can just grab the tid from the taxonomy term reference field, load the taxonomy term and grab the picture value with simple 3 lines of code. this will also keep an option open if they want to use the user picture for something else later ( I know he already said that he do not intend to use user picture).
    – Neo
    Commented Oct 6, 2013 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.