How To Display Postbit Images Based on a Profile Field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    How To Display Postbit Images Based on a Profile Field

    Possible applications:
    • Display a logo for a user's favorite baseball team in their posts.
    • User's religion.
    • ...sex.
    • ...favorite food.
    • etc.


    If you have a single selection profile field with predefined options that tell you something about the user then you can display images in the postbit based on the value the user has selected for that field. This is done using a template conditional.

    Go to your:

    Admin CP -> Styles & Templates -> Style Manager -> « » -> Postbit Templates -> postbit or postbit_legacy (depending on the layout you use)

    Use code like this:

    Code:
    <if condition="$post['[color=red]fieldX[/color]']">
    	<img src="images/fruit/$post[[color=red]fieldX[/color]].gif" alt="$post[[color=red]fieldX[/color]]" border="0" />
    </if>
    Where fieldX is the field number for the profile field as indicated in the:

    Admin CP -> User Profile Fields -> User Profile Field Manager

    Using fruits as an example, let's say the user selects banana from the profile field in their User CP. The above code would be activated because the user selected a value for that profile field, which would then display the img tag that ends up calling images/fruit/banana.gif.

    Notice how the img src uses the value of the profile field to call the appropriate image. As long as the menu options are "one word" options (no spaces) this method should work fine.

    The above example assumes you have uploaded the fruit images to the images/fruit directory.
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...