Announcement
Collapse
No announcement yet.
How To Add A Profile Field To The Postbit
Collapse
X
-
Copied from the 3.5 Quick Tips forum. This should still be valid for 3.6 but if you find something that doesn't work right in 3.6, let me know.
-
Appended data for 'How to add user profile field to postbit' thread.
The following might prove a useful additional post in the 'How to add a user profile to the postbit' thread, as an expansion on the first post in that thread:
For those interested in so doing (it seems to be a commonly requested design concept), the following code in the 'postbit' template will cause posts to display the profile field for 'Display Name' if the user has provided one; else it will display the poster's username (in the template example to follow, the X in 'fieldX' should be replaced with the number of the field in your profile fields configuration corresponding to 'Display Name', as indicated in AdminCP > User Profile Fields > User Profile Field Manager):
Code:<div id="postmenu_$post[postid]"> <if condition="$show['profile']"> <if condition="$post['fieldX']"> <a class="bigusername" href="member.php?$session[sessionurl]u=$post[userid]">$post[fieldX]</a> <else /> <a class="bigusername" href="member.php?$session[sessionurl]u=$post[userid]">$post[musername]</a> </if> <script type="text/javascript"> vbmenu_register("postmenu_$post[postid]", true); </script> <else /> $post[musername] </if> </div>
With the postbit template configured in this way, you do not need to make the 'Display Name' field mandatory in the profile; if the member provides a display name, it is used on posts. If not, their username is used instead.
Leave a comment:
-
For displaying multiple selection fields, you can separate each option with commas by expanding on the previous code. Add the blue code:
Code:<if condition="$comma = ''"></if> <if condition="$post['fieldX'] & 1"> $comma CODE TO DISPLAY IF OPTION 1 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 2"> $comma CODE TO DISPLAY IF OPTION 2 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 4"> $comma CODE TO DISPLAY IF OPTION 3 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 8"> $comma CODE TO DISPLAY IF OPTION 4 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 16"> $comma CODE TO DISPLAY IF OPTION 5 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 32"> $comma CODE TO DISPLAY IF OPTION 6 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 64"> $comma CODE TO DISPLAY IF OPTION 7 IS SELECTED <if condition="$comma = ', '"></if> </if> <if condition="$post['fieldX'] & 128"> $comma CODE TO DISPLAY IF OPTION 8 IS SELECTED <if condition="$comma = ', '"></if> </if>
Leave a comment:
-
How To Display Multiple Selection Profile Fields
Multiple selection fields present a problem when you try to display their values in the postbit. If you use the method described above then you will get a number displayed instead of the selected values. This is due to the method that is used for storing the selected values for multiple selection fields.
Multiple selection fields use a binary scheme to store the selected values. Each option is given a number value, like this:
option 1 = 2^0 = 1
option 2 = 2^1 = 2
option 3 = 2^2 = 4
option 4 = 2^3 = 8
option 5 = 2^4 = 16
option 6 = 2^5 = 32
option 7 = 2^6 = 64
option 8 = 2^7 = 128
etc...
Notice how each number is an integer power of 2. If you were to look at the stored value for a multiple selection field in natural binary format, then each bit would represent one of the options in the multiple selection field. For examlpe, if options 1 and 4 were selected then the stored value would look like this:
Code:2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0 binary # 0 0 0 0 1 0 0 1
In this case, the stored value is 9 (the sum of the "on" bits). This is also the number that would be displayed in the postbit if you were to use the above method to display the value of this field.
Under the current system, there is no built-in method to translate the stored value into the real value for use in the postbit. However, you can use a series of template conditionals to check each bit in the stored value and then display the appropriate code for each option:
Code:<if condition="$post['fieldX'] & 1"> CODE TO DISPLAY IF OPTION 1 IS SELECTED </if> <if condition="$post['fieldX'] & 2"> CODE TO DISPLAY IF OPTION 2 IS SELECTED </if> <if condition="$post['fieldX'] & 4"> CODE TO DISPLAY IF OPTION 3 IS SELECTED </if> <if condition="$post['fieldX'] & 8"> CODE TO DISPLAY IF OPTION 4 IS SELECTED </if> <if condition="$post['fieldX'] & 16"> CODE TO DISPLAY IF OPTION 5 IS SELECTED </if> <if condition="$post['fieldX'] & 32"> CODE TO DISPLAY IF OPTION 6 IS SELECTED </if> <if condition="$post['fieldX'] & 64"> CODE TO DISPLAY IF OPTION 7 IS SELECTED </if> <if condition="$post['fieldX'] & 128"> CODE TO DISPLAY IF OPTION 8 IS SELECTED </if>
Code:<if condition="$post['fieldX'] & 1"> CODE TO DISPLAY IF OPTION 1 IS SELECTED </if>
Code:<if condition="0000 1001 & 0000 0001"> CODE TO DISPLAY IF OPTION 1 IS SELECTED </if>
Leave a comment:
-
How To Add A Profile Field To The Postbit
If you haven't already, create a new profile field in your:
Admin CP -> User Profile Fields -> Add New User Profile Field
Users can enter their info into the profile field by going to their User CP. To display the information in posts you need to go to your:
Admin CP -> Styles & Templates -> Style Manager -> « » -> Postbit Templates -> postbit or postbit_legacy (depending on which layout you use)
Add this code:
Code:<if condition="$post['fieldX']"> $post[fieldX] </if>
Admin CP -> User Profile Fields -> User Profile Field Manager
You may also wish to add a label to the profile field. For example, if the profile field is for the user's location:
Code:<if condition="$post['fieldX']"> Location: $post[fieldX] </if>
Tags: None
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Leave a comment: