PDA

View Full Version : How To Display Postbit Images Based on a Profile Field



Jake Bunce
Wed 14th Apr '04, 8:33pm
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:



<if condition="$post['fieldX']">
<img src="images/fruit/$post[fieldX].gif" alt="$post[fieldX]" 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.