Announcement

Collapse
No announcement yet.

How do I check gender and display an image accordingly?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I check gender and display an image accordingly?

    On our site we added a custom field to user profiles that is also filled out at registration time. The field asks for a user's gender. We created new status icons for the "Online/Offline" indicator that reflect a user's gender, and wanted to write a small script that would check the gender of a user and select the appropriate icon. Since some of our registered users have not selected a gender (since it's a new field) I'd like a default image (the male one) to show up. How would I write this script?

    Thanks

  • #2
    See this thread.

    To set a default you would use this code (added the else block):

    Code:
    <if condition="$post['fieldX']">
    	<img src="images/fruit/$post[fieldX].gif" alt="$post[fieldX]" border="0" />
    <else />
    	<img src="images/fruit/male.gif" alt="male" border="0" />
    </if>
    Assuming the field option and corresponding image are named male.

    Let me know if you have any questions.

    Comment


    • #3
      Thank you, you guys rock

      Comment


      • #4
        Ok, I went into the postbit_legacy template to toss this in and down where the online status indicator stuff should be it just says: $post[onlinestatus]

        How do I incorporate this variable into that? Because I didn't see any <img> element surrounding the above. I did create three separate images for online status for each gender: Male_invisible/online/offline and Female_invisible/online/offline

        Thanks again in advance.

        Comment


        • #5
          Try editing the postbit_onlinestatus template.

          Without first testing it, I would say something like this should work (add the red code):

          Code:
          <if condition="$onlinestatus==0"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_offline<if condition="$post[fieldX]">_$post[fieldX]<else />_male</if>.gif" alt="<phrase 1="$user[username]">$vbphrase[x_is_offline]</phrase>" border="0" /></if>
          <if condition="$onlinestatus==1"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_online<if condition="$post[fieldX]">_$post[fieldX]<else />_male</if>.gif" alt="<phrase 1="$user[username]">$vbphrase[x_is_online_now]</phrase>" border="0" /></if>
          <if condition="$onlinestatus==2"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_invisible<if condition="$post[fieldX]">_$post[fieldX]<else />_male</if>.gif" alt="<phrase 1="$user[username]">$vbphrase[x_is_invisible]</phrase>" border="0" /></if>
          Where your images are uploaded under these names:

          user_offline_male.gif
          user_offline_female.gif
          user_online_male.gif
          user_online_female.gif
          user_invisible_male.gif
          user_invisible_female.gif

          Comment


          • #6
            still won't take, defaults to _male images

            I'm still not able to get this to work. When I implement the following code into the postbit_onlinestatus template, users that have gender set to female still use the _male image. Here is the code I'm using currently...

            Code:
            <if condition="$onlinestatus==0"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_offline<if condition="$post['field6']">_$post[field6]<else />_male</if>.png" alt="<phrase 1="$user[username]">$vbphrase[x_is_offline]</phrase>" border="0" /></if>
            <if condition="$onlinestatus==1"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_online<if condition="$post['field6']">_$post[field6]<else />_male</if>.png" alt="<phrase 1="$user[username]">$vbphrase[x_is_online_now]</phrase>" border="0" /></if>
            <if condition="$onlinestatus==2"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_invisible<if condition="$post['field6']">_$post[field6]<else />_male</if>.png" alt="<phrase 1="$user[username]">$vbphrase[x_is_invisible]</phrase>" border="0" /></if>
            Any ideas? Thanks.

            Comment


            • #7
              I see the problem. I overlooked one thing. You need to use the global scope. Here is the updated code. I added the blue code:

              Code:
              <if condition="$onlinestatus==0"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_offline<if condition="$GLOBALS[post][fieldX]">_{$GLOBALS[post][fieldX]}<else />_male</if>.gif" alt="<phrase 1="$user[username]">$vbphrase[x_is_offline]</phrase>" border="0" /></if>
              <if condition="$onlinestatus==1"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_online<if condition="$GLOBALS[post][fieldX]">_{$GLOBALS[post][fieldX]}<else />_male</if>.gif" alt="<phrase 1="$user[username]">$vbphrase[x_is_online_now]</phrase>" border="0" /></if>
              <if condition="$onlinestatus==2"><img class="inlineimg" src="$stylevar[imgdir_statusicon]/user_invisible<if condition="$GLOBALS[post][fieldX]">_{$GLOBALS[post][fieldX]}<else />_male</if>.gif" alt="<phrase 1="$user[username]">$vbphrase[x_is_invisible]</phrase>" border="0" /></if>

              Comment

              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
              Working...
              X