PDA

View Full Version : Using your User Profile Fields in your postbit templates (w/ all plugin method)


Lynne
09-12-2010, 10:00 PM
This article is written with the assumption that you have already created your own User Profile Fields in the User Profile Field Manager. If you need help with this, you may read about it in the manual here - http://www.vbulletin.com/docs/html/profile

For the Purposes of this article, I will be referring to "fieldx" as the name of your profile field. Your real name will be found in the User Profile Manager in the "Name" column - field1, field2, etc.

Adding the Profile Field to your postbit (or postbit_legacy) template

For Single-Line Text Box, Multiple-Line Text Box, Single-Selection Radio Buttons, and Single-Selection Menu

Method 1 - Modifying the Template Open the postbit or postbit_legacy template and find the area you want to add it to. For instance, to add it right after the user post count, find this:
<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw post.posts}</dd>And then, add this underneath:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook I have always found it easier to just use the existing $template_hooks in the template and write a plugin to add these. In this case, there is a $template_hook right where we want it, after the user post count:
{vb:raw template_hook.postbit_userinfo_right_after_posts}S o, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
For Multiple-Selection Menu and Multiple-Selection Checkbox

It is a bit more complicated for these two types of selections since the options selected are stored as a binary number. If you just display the field using the method above, you will get a number, not a list of options selected. So, in order to use these types of fields, you will have to use the method below. Here is a thead that will explain the binary scheme - http://www.vbulletin.com/forum/showthread.php?214234-How-To-Add-A-Profile-Field-To-The-Postbit

Method 1 - Modifying the Template Open the template and find the area you want to add it to. For instance, to add it right after the user post count, find this:
<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw post.posts}</dd>And then add this underneath (this is assuming the field has 5 options):
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>
<vb:if condition="$post['fieldx'] & 4">Your 3rd option</vb:if>
<vb:if condition="$post['fieldx'] & 8">Your 4th option</vb:if>
<vb:if condition="$post['fieldx'] & 16">Your 5th option</vb:if>
</dd>
</vb:if>Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field. Method 2 - Using a template_hook Find the template_hook you want to use. In this case, there is a $template_hook right where we want it, after the user post count:
{vb:raw template_hook.postbit_userinfo_right_after_posts}S o, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>';

if ($post['fieldx'] & 1) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 1rst option';
if ($post['fieldx'] & 2) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 2nd option';
if ($post['fieldx'] & 4) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 3rd option';
if ($post['fieldx'] & 8) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 4th option';
if ($post['fieldx'] & 16) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 5th option';

$template_hook['postbit_userinfo_right_after_posts'] .= '</dd>';
}
Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.More Advanced

If you like everything to be 'automatic' - meaning you don't have to supply any text at all, just use everything already stored in the database - then you can use a few of plugins to do the work for you.

Plugin 1 - This plugin is used to get the phrasegroup "cprofilefield" added for use in the page so that you may use $vbphrase[fieldx_title] to get the Profile Field Title you entered in the User Profile Field Manager.? hook location - init_startup
? Title - Add User Profile Fields to Postbit Templates - 1
? Plugin is Active - Yes
? Plugin PHP Code -
if (THIS_SCRIPT == 'showthread') $GLOBALS['phrasegroups'][] = 'cprofilefield';Plugin 2 - This plugin is used to get the fields you defined for the profile in the User Profile Field Manager.? hook location - showthread_postbit_create
? Title - Add User Profile Fields to Postbit Templates - 2
? Plugin is Active - Yes
? Plugin PHP Code -
if (THIS_SCRIPT == 'showthread') {
$profilefieldx = $vbulletin->db->query_first("SELECT profilefieldid, data, type FROM " . TABLE_PREFIX . "profilefield WHERE profilefieldid = x");
$post['profilefieldx'] = $profilefieldx;
}Plugin 3 - This plugin simply spits the data out into the postbit using the template_hook and using the phrase for the Title and the Options are all spit out with commas between them (if needed) into the postbit.? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates - 3
? Plugin is Active - Yes
? Plugin PHP Code -
// for single-line fields - using fieldy
if ($post['fieldy']) {
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldy_title]. '</dt> <dd>' .$post[fieldy]. '</dd>';
}

// for multiple-selection fields - using filedx
if ($post['fieldx'])
{
$fieldarrayx = $post['profilefieldx'];
fetch_profilefield_display($fieldarrayx, $post['fieldx']);
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldx_title]. '</dt> <dd>' .$fieldarrayx['value']. '</dd>';
}Change "fieldx" to your actual field name and the orange, purple, and brown fields should 'match-up' and have the same names.

Dave-M
09-14-2010, 02:09 PM
Hi Lynne, thanks for this, brilliant :)

I wonder if it would be possible for you to implement a dropdown for this, so that it's like wired1's mod? His has broken CSS at the moment and there's no sign of him being able to fix it soon, it would be fantastic if you could make something similar.

https://vborg.vbsupport.ru/showthread.php?t=248651

Lynne
09-14-2010, 02:15 PM
This is an article, not a modification. You may do whatever you want with the information found in here.

Lynne
09-20-2010, 02:00 PM
Thanks a lot for this article.

Is there a way to use specific User Profile Fields in vbcms article pages (Template vbcms_content_article_page)?

Cheers,
Martin
I'm sure there is, but I didn't cover that in this article. This article is just for the postbit(_legacy) template.

svoophod
09-22-2010, 09:30 PM
thanks so much, this is great!

COL NIL SATIS
09-26-2010, 05:13 PM
Thanks lynne..this is great!!!! top advice ..

djr
10-15-2010, 10:43 PM
Hi Lynne,

Is it easy to backport this to vB 3.8.6? Besides the obvious variable name changes, would the plugin solution work for vB 3.8.6 as well? (meaning: does vB 3.8.6 have the same hooks present?). Or does it need to be completely rewritten?

I'd love to have this a plugin solution for our vB 3.8.6 board, since it's getting tiresome to redo all the template changes after every upgrade (plus I like the plugin solution better)

Thanks for an excellent article! Much appreciated.

Lynne
10-15-2010, 11:00 PM
The method of calling the phrasegroup may have been different in 3.8, so you would have to change that. Other than that, you'd just have to change the html you are outputting as <li> wasn't used in 3.8 either. However, I've never tried it on my 3.8 board, so I can't say for sure.

voglermc
11-04-2010, 11:10 AM
<a href="album.php?{vb:raw session.sessionurl}u={vb:raw post.userid}" title="View {vb:raw post.username}'s Album" rel="nofollow">View {vb:raw post.username}'s Album</a>

Lynne
11-04-2010, 01:40 PM
You don't need user profile fields to link to album pages (unless you are doing something different?). I'm sure there is a mod or a thread about what you want to do if you are talking about just a plain link that has nothing to do with profile fields.

voglermc
11-04-2010, 02:02 PM
<a href="album.php?{vb:raw session.sessionurl}u={vb:raw post.userid}" title="View {vb:raw post.username}'s Album" rel="nofollow">View {vb:raw post.username}'s Album</a>

Lynne
11-04-2010, 02:29 PM
Then you should post in the main forums about it, not in some random article about the profile fields.

Black Tiger
11-30-2010, 07:32 PM
Looks very interesting. You told me this was possible to make compatible for v3.8.x by changing some html code.

Could you or somebody else tell me what exactly to change? I can read a bit of php, but don't know what to do with it, so I would really need a "look for this and replace with that" solution. It has no hurry though.;)

Thanks in advance!

Lynne
11-30-2010, 09:03 PM
Did you see this for 3.8? How To Add Custom Profile Field Information To The Postbit (https://vborg.vbsupport.ru/showthread.php?t=118896&highlight=profile)

The only thing I think she doesn't cover is doing it all via pluginand it isn't much different at all for 3.8.

Plugin 1
? hook location - init_startup
? Title - Add User Profile Fields to Postbit Templates - 1
? Plugin is Active - Yes
? Plugin PHP Code -
if (THIS_SCRIPT == 'showthread') $phrasegroups[] = 'cprofilefield';

Plugin 2
? hook location - showthread_postbit_create
? Title - Add User Profile Fields to Postbit Templates - 2
? Plugin is Active - Yes
? Plugin PHP Code -

if (THIS_SCRIPT == 'showthread') {
$profilefieldx = $vbulletin->db->query_first("SELECT profilefieldid, data, type FROM " . TABLE_PREFIX . "profilefield WHERE profilefieldid = x");
$post['profilefieldx'] = $profilefieldx;
}

Plugin 3
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates - 3
? Plugin is Active - Yes
? Plugin PHP Code -

// for single-line fields - using fieldy
if ($post['fieldy']) {
$template_hook['postbit_userinfo_right_after_posts'] .= '<div>' .$vbphrase[fieldy_title]. ': ' .$post[fieldy]. '</div>';
}

// for multiple-selection fields - using filedx
if ($post['fieldx'])
{
$fieldarrayx = $post['profilefieldx'];
fetch_profilefield_display($fieldarrayx, $post['fieldx']);
$template_hook['postbit_userinfo_right_after_posts'] .= '<div>' .$vbphrase[fieldx_title]. ': ' .$fieldarrayx['value']. '</div>';
}

Black Tiger
11-30-2010, 09:16 PM
Yep I have seen that, but she left out the Multiple Selection Menus (like in my post about the comma at vbulletin.com yesterday) and that is just what we needed. That part seems covered now in plugin 3 if I understand everything correctly.

Thank you very much for your time explaining it, we are going to try it.

Lynne
11-30-2010, 10:06 PM
You need to do plugin 1, 2, and 3, not just 3.

Black Tiger
11-30-2010, 10:20 PM
Yep, I understood, but thank you for making sure, because I see in my reply I was not clear about me understanding that we needed all 3.;)

Bundle
12-12-2010, 03:17 PM
Is there a way to make this only display if the user has filled in the profile field? e.g. if I tried to make a custom profile field about favourite food, is there a way to stop "Favourite Food: " appearing if the field is blank?

Cheers.

Lynne
12-12-2010, 06:55 PM
The if condition around it should make it so it doesn't show if it doesn't exist.

sulasno
01-08-2011, 11:15 PM
thanks for the link to this article

definitely a keeper

stl7997
01-11-2011, 02:53 AM
Thank you so much for this article! I was wondering where I need to add a break (see picture) to the code in the template. I would like a break to be done after the 'AE Assignments:' so that everything appears on the line below it.

Thanks in advance!

Lynne
01-11-2011, 03:02 AM
Thank you so much for this article! I was wondering where I need to add a break (see picture) to the code in the template. I would like a break to be done after the 'AE Assignments:' so that everything appears on the line below it.

Thanks in advance!
Can't you just add a <br /> where you want a break?

stl7997
01-11-2011, 09:32 AM
Can't you just add a <br /> where you want a break?

Yes that is exactly what I want to do, however I'm a complete noob to PHP. I've tried adding the <br /> in different places to the code but cannot get the desired results.

Where would I add the <br /> in this code? Or is this even the right place to place it?

Sorry for such rookie questions :o

// for single-line fields - using fieldy
if ($post['fieldy']) {
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldy_title]. '</dt> <dd>' .$post[fieldy]. '</dd>';
}

// for multiple-selection fields - using filedx
if ($post['fieldx'])
{
$fieldarrayx = $post['profilefieldx'];
fetch_profilefield_display($fieldarrayx, $post['fieldx']);
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>' .$vbphrase[fieldx_title]. '</dt> <dd>' .$fieldarrayx['value']. '</dd>';
}

Lynne
01-11-2011, 08:16 PM
Put it right after the </dt> and before the <dd> for the field you are adding.

stl7997
01-12-2011, 02:20 AM
Put it right after the </dt> and before the <dd> for the field you are adding.

:up::D

Thanks Lynne!

Sarcoth
01-20-2011, 01:28 AM
Can we set this up so only certain users can see postbit addon?
if (is_member_of($vbulletin->userinfo, 5, 6, 7))
{
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}
}

I can't seem to get that part to work. Thanks.

Lynne
01-20-2011, 03:36 AM
It could be you need to globalize $vbulletin if you are using that variable.

Sarcoth
01-20-2011, 03:59 AM
Can we set this up so only certain users can see postbit addon?
if (is_member_of($vbulletin->userinfo, 5, 6, 7))
{
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}
}

I can't seem to get that part to work. Thanks.

It could be you need to globalize $vbulletin if you are using that variable.

Thanks Lynne. I know I had tried that earlier and thought it did not work. Going over my notes I see I used "$global $vbulletin;". I needed to leave out the first $ to fix the problem.

I thought globalizing it could be a security risk in some cases. Is there a problem doing that in this plugin?

Thank you again for the help on that. Now I can go to sleep. :)

Special Pages
03-13-2011, 08:55 PM
Very good Lynne. Keep up the good work!

mikem164
03-18-2011, 04:28 PM
Just did this and it turned out phenomenal! A big THANKS!

ExciterNL
05-08-2011, 08:19 AM
Thanks

Booyakan
05-30-2011, 04:47 PM
Thanks for this!

Also, I have one question...Let's say I use this in my template..

<vb:if condition="$post['field5']"><dt>My Field5</dt> <dd>{vb:raw post.field5}</dd></vb:if>


Is there anyway to still show it to guests? It disappears on me when I log out. Same holds true for using the plugin method.

Lynne
05-30-2011, 05:07 PM
If the field is private (this has to do with your options when setting up the user profile field), then it won't show.

Booyakan
05-30-2011, 05:52 PM
If the field is private (this has to do with your options when setting up the user profile field), then it won't show.

Thanks Lynne, that's what it was.

Killeglass
05-31-2011, 03:58 PM
Hello

I am trying to add this directly under the username

<vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>

when I do I get it formatted as


My Field
fieldx

where I would like


My Field fieldx


Any suggestions greatly appreciated


:)

Lynne
05-31-2011, 04:20 PM
Can we get a link to see this?

Killeglass
05-31-2011, 04:31 PM
Can we get a link to see this?

Thank you Lynne!!


http://www.scikotics.com/forums


Tim :)

EDIT

here is how I have it installed

<div class="username_container">
<vb:if condition="$post['userid']">
{vb:raw memberaction_dropdown}
{vb:raw post.onlinestatus}
<vb:else />
<span class="username guest">{vb:raw post.musername}</span>
</vb:if>
</div>
<span class="usertitle">
{vb:raw post.usertitle}
</span>
<vb:if condition="$post['field6']"><dt>Name</dt> <dd>{vb:raw post.field6}</dd></vb:if>
<vb:if condition="$post['field5']"><dt>Ride</dt> <dd>{vb:raw post.field5}</dd></vb:if>
<vb:if condition="$post['rank']">
<span class="rank">{vb:raw post.rank}</span>

Lynne
05-31-2011, 04:40 PM
You need to put it under the userinfo_extra div. Or, put it in it's own div with that class in order to get it layed out correctly.

Killeglass
05-31-2011, 04:52 PM
Thank you again Lynne.

Unfortunately I am a bit old and senile LOL

What would the div class be? just guessing here.

<div>
<vb:if condition="$post['field6']"><dt>Name</dt> <dd>{vb:raw post.field6}</dd></vb:if>
<vb:if condition="$post['field5']"><dt>Ride</dt> <dd>{vb:raw post.field5}</dd></vb:if></div>

Would really like to keep this field up top if possible


Tim :)


EDIT


<dl class="userinfo_extra">

I added another instance and used that to achieve whats needed. I hope no advewrse reactions from using it

Thanks again!!!

Tim :)

8thos
06-23-2011, 10:51 PM
Cool post.

steve-iv
07-03-2011, 09:11 AM
Hi guys,

just have a question regarding to display a phrase in my profile field

Let's say i created field9 -> and a language dependend title in field9_title.

Now I edited the postbitlegacy template:


<vb:if condition="$post[field9]">
<dt>{vb:rawphrase field9_title}</dt>
<dd>{vb:raw post.field9}</dd>
</vb:if>


The problem is, post.field9 is working. Now I want to display the content of the phrase variable called field9_title.

But why is vb:rawphrase not working with field9_title? And what can I do to get it working?

And why is vbphrase not working?

Thanks!

Lynne
07-03-2011, 04:08 PM
You need to create a plugin to add that phrasegroup to the page. The plugin is shown in the first post.

(Sorry, I'm stuck on dialup right now and not going to go look it up and post it again.)

Nerror
07-12-2011, 06:10 AM
This is great and just what I was looking for, thanks. :)

One question though, how do I add commas for the multi-selection fields?

I used method 1 and have this code, which works:
<vb:if condition="$post['field5']"><dt>Spil</dt><dd>
<vb:if condition="$post['field5'] & 1">Ingen</vb:if>
<vb:if condition="$post['field5'] & 2">WoW</vb:if>
<vb:if condition="$post['field5'] & 4">SWTOR</vb:if>
<vb:if condition="$post['field5'] & 8">Rift</vb:if>
<vb:if condition="$post['field5'] & 16">Andet</dd>
</vb:if>
and I tried modifying the code from here (https://www.vbulletin.com/forum/showthread.php/214234-How-To-Add-A-Profile-Field-To-The-Postbit?p=1278858&viewfull=1#post1278858) to vBulletin 4.x but I am not a coder at all, so adding commas didn't work. :p

Any help much appreciated!

kdog316
12-10-2011, 06:42 AM
works great but is there a reason if you see in the second post it doesnt show the label for the fields after making a post until I refresh the page. Also announcements never show the labels.

https://vborg.vbsupport.ru/external/2011/12/44.jpg

I went with the more advanced method of inserting this stuff

Ramsesx
01-19-2012, 09:25 AM
A nice tutorial Lynne, thanks.

michelle86
03-11-2012, 07:59 PM
Thank you thank you thank you! 5 stars!

EasyEazy
04-01-2012, 02:26 AM
Great work

Thanks

michaelbang
04-16-2012, 02:22 PM
I'm struggeling to get my new profilefield right under the username. I've read the previous post about it, but still can't figure out where to your code <vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>.

Is it in postbit or postbit legacy? And exactly where do I put it? I've tried several places, with no succes.

Thanks a million. :)

Lynne
04-16-2012, 03:32 PM
Do you have your userinfo on top of the post (postbit) or on the left side of the post (postbit_legacy)? That determines which template to edit.

Tri@de
06-08-2012, 02:16 PM
There's a way to use profile fields also in other pages like cms articles?

Lynne
06-08-2012, 03:34 PM
There's a way to use profile fields also in other pages like cms articles?
I'm sure there is, but this article is not about that, it is about using them in the postbit template.

Cognitio
07-09-2012, 09:08 PM
I've set this up using the advanced method but when it displays I only get the binary number and not the array of choices selected... what am I doing wrong?

Lynne
07-09-2012, 11:47 PM
I've set this up using the advanced method but when it displays I only get the binary number and not the array of choices selected... what am I doing wrong?
I don't know. How about a screen shot of your admincp profile field set up and the exact code/hook for your plugin.

Cognitio
07-12-2012, 01:02 AM
I actually altered this into another mod - Profile Intro. The mod adds a memberprofile header that displays custom profile fields defined from the usercp. The mod itself displays input and textarea fields fine, but when it comes to multi_select fields they only display the binary code. I searched through and found this article and attempted to alter it into the Profile Intro mod, the basic function that would require a template modification every time I change a custom field works fine, but I rather have the more advanced option work for ease of use.

Here's the template code I used:
<template name="memberinfo_block_intro" templatetype="template" date="1321436160" username="phpdesk" version="1.0.3"><![CDATA[ <div class="collapse intro_block">
<vb:if condition="$userinfo[$introtitle]"><h2><span><a href="http://{vb:raw userinfo.$introlink}">{vb:raw userinfo.$introtitle}</a> | ({vb:raw userinfo.$introloc})</span></h2></vb:if>
<div class="text<vb:if condition="$userinfo[$introtitle]"> noborder</vb:if>"><p>Skills: {vb:raw userinfo.$introtypedef2} |
<vb:if condition="$userinfo[$introtype] & 1"> {vb:raw userinfo.$introtype}-1,</vb:if>
<vb:if condition="$userinfo[$introtype] & 2"> {vb:raw userinfo.$introtype}-2,</vb:if>
<vb:if condition="$userinfo[$introtype] & 4"> {vb:raw userinfo.$introtype}-3,</vb:if>
<vb:if condition="$userinfo[$introtype] & 8"> {vb:raw userinfo.$introtype}-4,</vb:if>
<vb:if condition="$userinfo[$introtype] & 16"> {vb:raw userinfo.$introtype}-5,</vb:if>
<vb:if condition="$userinfo[$introtype] & 32"> {vb:raw userinfo.$introtype}-6,</vb:if>
<vb:if condition="$userinfo[$introtype] & 64"> {vb:raw userinfo.$introtype}-7,</vb:if>
<vb:if condition="$userinfo[$introtype] & 128"> {vb:raw userinfo.$introtype}-8,</vb:if>
<vb:if condition="$userinfo[$introtype] & 256"> {vb:raw userinfo.$introtype}-9,</vb:if>
<vb:if condition="$userinfo[$introtype] & 512"> {vb:raw userinfo.$introtype}-10,</vb:if>
<vb:if condition="$userinfo[$introtype] & 1024"> {vb:raw userinfo.$introtype}-11,</vb:if>
<vb:if condition="$userinfo[$introtype] & 2048"> {vb:raw userinfo.$introtype}-12,</vb:if>
<vb:if condition="$userinfo[$introtype] & 4096"> {vb:raw userinfo.$introtype}-13,</vb:if>
<vb:if condition="$userinfo[$introtype] & 8192"> {vb:raw userinfo.$introtype}-14,</vb:if>
<vb:if condition="$userinfo[$introtype] & 16384"> {vb:raw userinfo.$introtype}-15,</vb:if>
<vb:if condition="$userinfo[$introtype] & 32768"> {vb:raw userinfo.$introtype}-16,</vb:if>
<vb:if condition="$userinfo[$introtype] & 65536"> {vb:raw userinfo.$introtype}-17,</vb:if>
<vb:if condition="$userinfo[$introtype] & 131072"> {vb:raw userinfo.$introtype}-18,</vb:if>
<vb:if condition="$userinfo[$introtype] & 262144"> {vb:raw userinfo.$introtype}-19,</vb:if>
<vb:if condition="$userinfo[$introtype] & 524288"> {vb:raw userinfo.$introtype}-20,</vb:if>
<vb:if condition="$userinfo[$introtype] & 1048576"> {vb:raw userinfo.$introtype}-21,</vb:if>
<vb:if condition="$userinfo[$introtype] & 2097152"> {vb:raw userinfo.$introtype}-22,</vb:if>
<vb:if condition="$userinfo[$introtype] & 4194304"> {vb:raw userinfo.$introtype}-23,</vb:if>
<vb:if condition="$userinfo[$introtype] & 8388608"> {vb:raw userinfo.$introtype}-24,</vb:if>
<vb:if condition="$userinfo[$introtype] & 16777216"> {vb:raw userinfo.$introtype}-25,</vb:if>
<vb:if condition="$userinfo[$introtype] & 33554432"> {vb:raw userinfo.$introtype}-26,</vb:if>
<vb:if condition="$userinfo[$introtype] & 67108864"> {vb:raw userinfo.$introtype}-27,</vb:if>
<vb:if condition="$userinfo[$introtype] & 134217728"> {vb:raw userinfo.$introtype}-28,</vb:if>
<vb:if condition="$userinfo[$introtype] & 268435456"> {vb:raw userinfo.$introtype}-29,</vb:if>
<vb:if condition="$userinfo[$introtype] & 536870912"> {vb:raw userinfo.$introtype}-30,</vb:if>
<vb:if condition="$userinfo[$introtype] & 1073741824"> {vb:raw userinfo.$introtype}-31</vb:if>
</p></div>
<div class="text<vb:if condition="$userinfo[$introtitle]"> noborder</vb:if>"><p>{vb:raw userinfo.$introtext}</p></div>
</div>]]></template>

and here's the plugins code I used (profileintro_typefield is defined as the profilefieldid already):
<plugin active="1" executionorder="5">
<title>Add User Profile Fields to Postbit Templates - 1</title>
<hookname>init_startup</hookname>
<phpcode><![CDATA[if (THIS_SCRIPT == 'member') $GLOBALS['phrasegroups'][] = 'cprofilefield';]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>Add User Profile Fields to Postbit Templates - 2</title>
<hookname>member_build_blocks_start</hookname>
<phpcode><![CDATA[if (THIS_SCRIPT == 'member')
{
$typefielddef = $vbulletin->options['profileintro_typefield'];
$profilefieldx = $vbulletin->db->query_first("SELECT profilefieldid, type, data FROM " . TABLE_PREFIX . "profilefield` WHERE profilefieldid = $typefielddef");
$userinfo['profilefieldx'] = $profilefieldx;
}]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>Cache: Profile Intro Templates</title>
<hookname>cache_templates</hookname>
<phpcode><![CDATA[if (THIS_SCRIPT == 'member')
{
$cache[] = 'memberinfo_block_intro';
}


if(THIS_SCRIPT=='css')
{
$cache[] = 'profile-intro.css';
}]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>Profile: Display Intro Block</title>
<hookname>member_build_blocks_start</hookname>
<phpcode><![CDATA[if (
$vbulletin->options['profileintro']
&& is_member_of( $userinfo, explode( ',', $vbulletin->options['profileintro_groups'] ) )
)
{
$introtitle = 'field' . $vbulletin->options['profileintro_titlefield'];
$introtype = 'field' . $vbulletin->options['profileintro_typefield'];
$introtext = 'field' . $vbulletin->options['profileintro_textfield'];
$introlink = 'field' . $vbulletin->options['profileintro_linkfield'];
$introloc = 'field' . $vbulletin->options['profileintro_locfield'];

if ( $introtype )
{
$fieldarrayx = $userinfo['profilefieldx'];
fetch_profilefield_display($fieldarrayx, $introtype);
$introtypedef2 = $fieldarrayx["value"];
}

if ( $userinfo["$introtext"] )
{
$userinfo["$introtitle"] = addslashes($userinfo["$introtitle"]);

// parse bbcode
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
$userinfo["$introtext"] = $bbcode_parser->parse(addslashes($userinfo["$introtext"]),0, true);

if ($vbulletin->versionnumber < '4.0.8')
{
$template = '<div class="member_tabs">';
}
else
{
$template = '<div class="tabbackground" id="profile_tabs">';
}

$templater = vB_Template::create('memberinfo_block_intro');
$templater->register('introtitle', $introtitle);
$templater->register('introtype', $introtype);
$templater->register('introtext', $introtext);
$templater->register('introlink', $introlink);
$templater->register('introloc', $introloc);
$templater->register('userinfo', $userinfo);
$templater->register('introtypedef2', $introtypedef2);

$vbulletin->templatecache['MEMBERINFO'] = str_replace(
$template, $template . $templater->render(),
$vbulletin->templatecache['MEMBERINFO']
);
}


}]]></phpcode>
</plugin>

Attached are two screen shots, the first is of the display results of the Profile Intro mod within the member.php, and the second screen shot is of the admincp of the customfields as requested. As seen in the first screen shot, the array is correctly shown in the 'About Me' section (which I couldn't find the coding on what to copy to project in the mod), but in the Profile Intro mod it's the binary code and the text I supplied within the coding to define each multi_select option.

Cognitio
08-02-2012, 02:59 PM
I'm just going to assume I'm being ignored...

TheSupportForum
09-09-2012, 08:49 AM
hi need help converting this into a plugin for postbit_legacy for the following template hook

$template_hook['postbit_userinfo_right_after_posts']



<vb:if condition="$post['field5']">
<dt>eRepublik</dt> <dd><a href="http://www.erepublik.com/en/citizen/profile/{vb:raw post.field5}"><img src="http://www.legijastranaca.com/images/erep/citizen.png" alt="Citizen link" width="25" height="24" border="0"></a><a href="http://www.erepublik.com/en/main/messages-compose/{vb:raw post.field5}"><img src="http://www.legijastranaca.com/images/erep/message.png" alt="Message Citizen on eRepublik" width="24" height="24" border="0"></a><a href="http://www.erepublik.com/en/economy/donate-items/{vb:raw post.field5}"><img src="http://www.legijastranaca.com/images/erep/donate.png" alt="Donate Items" width="24" height="24" border="0"></a></vb:if>

Lynne
09-09-2012, 02:55 PM
Did you try converting it using this as an example?
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}

omega79
09-25-2012, 09:45 AM
is there any plugin to download to just simply change it without adding code to some templates?

Lynne
09-25-2012, 02:37 PM
is there any plugin to download to just simply change it without adding code to some templates?
Under the More Advanced section of my post, I posted the plugin codes. I cannot write a plugin for you to download since you need to enter the fieldid.

TheSupportForum
09-25-2012, 06:57 PM
Did you try converting it using this as an example?
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}

Lynee i always have issues inserting hyperlinks

i want to do something like this


if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' http://www.domain.com/ .$post[fieldx]. '>link</a></dd>';
}

Lynne
09-25-2012, 08:49 PM
You need to use the <a> tag for links - http://www.w3schools.com/tags/tag_a.asp and please use double-quotes in the tag, not single-quotes since the single-quotes are being used in the equation.

omega79
09-26-2012, 07:38 AM
i am just very new to all this so i have no idea how to do it ...
isn't there a way you can put a form in the pluginconfiguration where the plugin-user could type in or choose the fieldID ?

but well if needed i will probably finishing my community first and after i went live i can look into this again ...

still having headaches over other things in VBB ... have to learn alot ;)

Lynne
09-26-2012, 04:09 PM
I already have it in a form where all you have to do is change the field id. This is an article, not a modification. If you don't know how to do it, then I suggest you try it out on your test site.

omega79
10-02-2012, 09:08 AM
okay thank you very much :D
it all looks very complicated if you are new to vbulletin ...
but after some time it gets more simple ...
nice work you done here :D

CentralGarrison
02-26-2013, 02:39 PM
I'm sorry if this is inappropriate to ask here, but reading through this guide it looks like the same method could be used to put custom profile fields into the user's signature. Which templates would I need to edit to force a custom field to always be displayed in a user's signature?

EDIT: Nevermind, please disregard. I found what I needed in the postbit_legacy template! Thank you!

Mysterious Ride
04-23-2013, 03:13 PM
Method 2 - Using a template_hook I have always found it easier to just use the existing $template_hooks in the template and write a plugin to add these. In this case, there is a $template_hook right where we want it, after the user post count:
{vb:raw template_hook.postbit_userinfo_right_after_posts}S o, we would create a plugin with these specifications:
? hook location - postbit_display_complete
? Title - Add User Profile Fields to Postbit Templates
? Plugin is Active - Yes
? Plugin PHP Code -
if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>' .$post[fieldx]. '</dd>';
}Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.


I tried to read on how to make this a hyperlink from what others asked, but I got confused. This is the method that you posted that I want to use and what's going to be placed into the profile field is a link to profile post that the member posted for a character. What I trying to get it to look like is this:

Join Date:
Posts:
Character Profile (http://www.ofagewizards.com/forums/forum.php)

Even if its the whole Character Profile is the hyperlink that will take member directly to the character profile will work. I believe you said that I would have to use the <a> tag, but I'm not sure how to insert it into the code you already have.

Lynne
04-23-2013, 03:54 PM
Something like:

$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>Character</dt> <dd><a href="' .$post[fieldx]. '">Profile</a></dd>';
}

I haven't tested it, but I think it should work.

Mysterious Ride
04-24-2013, 08:20 AM
That didn't work, I got this error at the top of my board. I tried just doing the regular method two you have posted, but the profile field didn't show up under the post count either.

Lynne
04-24-2013, 04:20 PM
And what was the error? And what was the *exact* code you entered into the plugin?

Mysterious Ride
04-25-2013, 01:01 AM
Sorry, I tried it again and it worked perfectly. I must have not posted something right. I got the error because I left out the:

if ($post['fieldx'])
{

I thought I added it when I tried a second time, but I didn't get an error message nor did anything show up. But here's the completed code for Method 2 that works perfectly:

if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My fieldX</dt> <dd><a href="' .$post[fieldx]. '">My Link</a></dd>';
}

The My Link can be anything anyone what's it to be.

I also adjusted the code so that it fits Method 1 and I tested it and it works great to. It still goes in the same place you said.

<vb:if condition="$post['fieldx']"><dt>My fieldX</dt> <dd><a href="{vb:raw post.fieldx}">My Link</a></dd></vb:if>

I included an attachment to show the end result.

kiddo
08-22-2013, 06:22 PM
So I copied the same code from Location to use for other custom profile fields. When I did this, it showed up, but the name didn't as you can see in the image below. Any help??

The custom profile field's name is PSN so for the code

{vb:rawphrase} I put {vb:rawphrase PSN}\

EDIT: FIXED IT! I just completely removed the vb:rawphrase and simply added PSN to the "MyField" part and it worked!

afmarko99
02-15-2014, 04:15 PM
Thank you very much Lynne

akxt660
04-03-2014, 11:58 PM
I want to show images in postbit, related to the selected options by the user in the Multiple Choice Menu.

The below code works just in "Single Selection Menu:

<vb:if condition="$post['fieldX']"> <img src="{vb:raw post.fieldX}.png" /> </ a> </ vb: if>

But how do I work on Multiple Choice Menus?

In the image below you can view the images, but it performed with the Single Choice Menus:

https://vborg.vbsupport.ru/external/2014/04/48.jpg

In this case the user should select four options in Multiple Choice Menu.
These images refer to flags that users rescued

ozzy47
04-04-2014, 12:08 AM
Did you follow all the instructions in the first post?

For Multiple-Selection Menu and Multiple-Selection Checkbox

It is a bit more complicated for these two types of selections since the options selected are stored as a binary number. If you just display the field using the method above, you will get a number, not a list of options selected. So, in order to use these types of fields, you will have to use the method below. Here is a thead that will explain the binary scheme - http://www.vbulletin.com/forum/showt...To-The-Postbit (http://www.vbulletin.com/forum/showthread.php?214234-How-To-Add-A-Profile-Field-To-The-Postbit)

Method 1 - Modifying the Template Open the template and find the area you want to add it to. For instance, to add it right after the user post count, find this:

<dt>{vb:rawphrase 'posts'}</dt> <dd>{vb:raw post.posts}</dd> And then add this underneath (this is assuming the field has 5 options):


<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>
<vb:if condition="$post['fieldx'] & 4">Your 3rd option</vb:if> <vb:if condition="$post['fieldx'] & 8">Your 4th option</vb:if>
<vb:if condition="$post['fieldx'] & 16">Your 5th option</vb:if>
</dd>
</vb:if>Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.

akxt660
04-04-2014, 12:54 AM
Yes. All ok now!

I found a problem here:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>

correct is:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd> </vb:if>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>

I get string error because of this small problem!

ozzy47
04-04-2014, 12:56 AM
Excellent, glad you got it sorted. :)

Protonus
04-29-2014, 01:12 AM
TL;DR - how can I display a multi line textbox custom profile field, with line breaks preserved, in the postbit?

I've got a Multi Line Text Box, custom profile field, that I would like to display in my legacy postbit. I'm using this code from the OP:

<vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>

And it works great! But it doesn't respect line breaks, that users entered into this profile field, which makes it look really weird when you have more than one item listed.

I found a post mentioning this:


Multiple Line Text Boxes

While I don't recommend displaying these in the postbit as they can contain a large amount of information, they are done in the exact same way as the single line text box.

Note: The text entered will display all on one line, not in multiple lines as added to the text box and displayed in the profile page.

But... no mention on how to fix it? Thanks in advance!

Lynne
04-29-2014, 03:00 AM
You'd have to look at the array and put line feeds between the items. I haven't ever needed to look into this, so I can't offer a solution to you.

kh99
04-30-2014, 09:09 AM
You might try:
<dd><pre>{vb:raw post.fieldx}</pre></dd>


but I haven't tried it myself.

Protonus
04-30-2014, 08:13 PM
You might try:
<dd><pre>{vb:raw post.fieldx}</pre></dd>
but I haven't tried it myself.

Thank you for the suggestion! It DOES preserve the line breaks now, however, it also doesn't word wrap now, which means it allows long lines to spill into the post area from the postbit. Doh!

So, close, but I had to roll back due to the spill over issue.

DreadsUK
04-30-2014, 08:57 PM
oh man im so shit at this lol

ok, so vB4.2.2 and editing in postbit template

The field i've created is gender with 2 options male or female.

http://s9.postimg.org/5qp9yvmf3/Screen_shot_2014_05_01_at_06_38_27.png

Here is the code i've got in there. Its not working and i bet one of you guys will take 1 look and it will be so obvious lol

https://vborg.vbsupport.ru/external/2014/04/1.png

Lynne
05-01-2014, 05:05 PM
It's "field7", not "Field7".

DreadsUK
05-02-2014, 06:05 PM
<vb:if condition="$post['field7']"><dt>Gender</dt> <dd>{vb:raw post.field7}</dd></vb:if>

Not working

Mark.B
05-02-2014, 06:22 PM
Take off the conditionals so you just have this:
<dt>Gender</dt> <dd>{vb:raw post.field7}</dd>

Does anything show up now?

This is really a test that you are editing the correct template in the correct style, since now, even if your field id was wrong you should at least see "Gender" in the postbit.

Lynne
05-02-2014, 06:27 PM
Are you sure the poster has even set the gender in their profile?

DreadsUK
05-02-2014, 06:34 PM
Are you sure the poster has even set the gender in their profile?

Yea, the poster is me hehe. good question tho :p

--------------- Added 1399059505 at 1399059505 ---------------

AHHHH, i was editing

'postbit' not 'postbit_legacy'

Mark.B
05-02-2014, 07:13 PM
This is really a test that you are editing the correct template


AHHHH, i was editing

'postbit' not 'postbit_legacy'

The old ones are the best. ;)

jagtpf
06-23-2015, 11:13 AM
Have been trying to use method 2 ...

This works >>>>

if ($post[field40])
{
$ImagePath = vB_Template_Runtime::fetchStyleVar('imgdir_misc'). '/critique/nocritique.png';
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br /><dt>Critique Level</dt><br /> <dd><img src="' . $ImagePath . '"/></dd>';
}

Yielding both Critique Level: and an image.

Adding conditional doesn't, if there is just one conditional I get Critique Level: and a broken image link; the only difference is the "& 4" - If I use with three conditionals I get 3 * Critique Level: s and 3 broken image links .... It also seems as though it is ignoring the "if" statement because it shows on every profile.>>>>

if ($post[field40])
{
if ($post[field40] & 4)
$ImagePath = vB_Template_Runtime::fetchStyleVar('imgdir_misc'). '/critique/nocritique.png';
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br /><dt>Critique Level</dt><br /> <dd><img src="' . $ImagePath . '"/></dd>';
}

I can hazard a guess that using three conditionals there could be a confusion over $ImagePath, but surely it should work with just the one condition ?

I'm missing something rather simple I think ?!

Lynne
06-23-2015, 04:52 PM
You need some parenthesis after your second condition (why are you using a second one anyway?).

if ($post[field40])
{
if ($post[field40] & 4)
{
$ImagePath = vB_Template_Runtime::fetchStyleVar('imgdir_misc'). '/critique/nocritique.png';
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br /><dt>Critique Level</dt><br /> <dd><img src="' . $ImagePath . '"/></dd>';
}
}

jagtpf
06-25-2015, 07:08 AM
Not too sure what you mean by "why am I using a second condition...."

I'm following your method 2 :


if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>';

if ($post['fieldx'] & 1) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 1rst option';
if ($post['fieldx'] & 2) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 2nd option';
if ($post['fieldx'] & 4) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 3rd option';
if ($post['fieldx'] & 8) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 4th option';
if ($post['fieldx'] & 16) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 5th option';

$template_hook['postbit_userinfo_right_after_posts'] .= '</dd>';
}


but for 3 conditions. But even ignoring the conditional, I can't get a true result from conditional statement for any of ; ($post[field40] & 1), ($post[field40] & 2) or ($post[field40] & 4), whilst I can from ($post[field]).

[field40] contains 3 radio buttons.

Looks like I need to keep hammering at it ....

Lynne
06-25-2015, 05:26 PM
Since you didn't use the code tags, it looked like your code was not all on one-line, which it needs to be if you don't use the parenthesis.

You don't use that code for a radio button though. That code is for Multiple-Selection Menu and Multiple-Selection Checkbox profile fields. You need to use the code for For Single-Line Text Box, Multiple-Line Text Box, Single-Selection Radio Buttons, and Single-Selection Menu profile fields.

ProfC
07-09-2015, 08:44 PM
Hi Lynne,

Is it possible to display a different image on the postbit depending on the option chosen on a single-selection menu?

Example: "What is your favourite colour?"
Red
Blue
Green
Orange

I've used method one but am suspecting that method two may actually be more suitable for this task.

Thank you in advance,

ProfC.

Lynne
07-10-2015, 03:01 PM
You could use either template edits or a plugin to do what you want. In the examples I show, just replace 'Your 1rst option' with '<img src="image.png" alt="Red Image" height="xx" width="yy">'

ProfC
07-10-2015, 03:25 PM
You could use either template edits or a plugin to do what you want. In the examples I show, just replace 'Your 1rst option' with '<img src="image.png" alt="Red Image" height="xx" width="yy">'

Thank you! I'll take a look and see what I get. :)

friendlymela
07-21-2015, 03:28 PM
Good advices thanks for share this

ProfC
07-24-2015, 12:05 PM
I'm having a bit of trouble somewhere with this. I decided to go the plugin method for multiple selection fields, as it seemed to offer the means to set different things to display based on the option selected. Unfortunately, I haven't been able to get any further than it displaying "house memberships" (the field name) on the postbit (http://gyazo.com/eeadf59d2941d834f9adc98b8e8a7f2d).

I'm not sure whether I've even used the right method or not but the "single selection menu" method didn't appear to have the options to display a different result based on what was selected in the profile menu.

Would it be possible for someone to tell me where I've gone wrong? (I get the sensation I'll be asking this a lot -sigh-) Thank you in advance :)

Plugin code:
if ($post['field17'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>House Membership</dt> <dd>';

if ($post['field17'] & 1) $template_hook['postbit_userinfo_right_after_posts'] .= '<img src="http://i.imgur.com/TdZqV1q.gif?1" title="Ravenclaw" alt="Ravenclaw" />';
if ($post['field17'] & 2) $template_hook['postbit_userinfo_right_after_posts'] .= 'Montresor';
if ($post['field17'] & 4) $template_hook['postbit_userinfo_right_after_posts'] .= 'Astor';
if ($post['field17'] & 8) $template_hook['postbit_userinfo_right_after_posts'] .= 'Lore';
if ($post['field17'] & 16) $template_hook['postbit_userinfo_right_after_posts'] .= 'Bluteisen-Ravenclaw';
if ($post['field17'] & 32) $template_hook['postbit_userinfo_right_after_posts'] .= 'Pendrake';

$template_hook['postbit_userinfo_right_after_posts'] .= '</dd>';
}

MarkFL
07-24-2015, 12:22 PM
You want to use "==" instead of "&" in your conditionals. However, might I suggest using a switch statement instead?

if ($post['field17'])
{
switch ($post['field17']) {
case 1:
$hmtitle = '<img src="http://i.imgur.com/TdZqV1q.gif?1" title="Ravenclaw" alt="Ravenclaw" />';
break;
case 2:
$hmtitle = 'Montresor';
break;
case 4:
$hmtitle = 'Astor';
break;
case 8:
$hmtitle = 'Lore';
break;
case 16:
$hmtitle = 'Bluteisen-Ravenclaw';
break;
case 32:
$hmtitle = 'Pendrake';
break;
}
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>House Membership</dt> <dd>' . $hmtitle . '</dd>';
}

ProfC
07-24-2015, 01:48 PM
Thank you; although it appears I'm getting the same result using your version as I am with the one I added following the article.

MarkFL
07-24-2015, 02:46 PM
What hook location are you using?

ProfC
07-24-2015, 02:52 PM
"postbit_display_complete" as mentioned in the article.

MarkFL
07-24-2015, 03:03 PM
Okay, try using the plugin code:

if ($post['field17'])
{
switch ($post['field17']) {
case 1:
$hmtitle = '<img src="http://i.imgur.com/TdZqV1q.gif?1" title="Ravenclaw" alt="Ravenclaw" />';
break;
case 2:
$hmtitle = 'Montresor';
break;
case 4:
$hmtitle = 'Astor';
break;
case 8:
$hmtitle = 'Lore';
break;
case 16:
$hmtitle = 'Bluteisen-Ravenclaw';
break;
case 32:
$hmtitle = 'Pendrake';
break;
default:
$hmtitle = 'Default';
}
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>House Membership</dt> <dd>' . $hmtitle . '</dd>';
}

What do you get now?

ProfC
07-24-2015, 03:13 PM
"House Membership: Default (http://gyazo.com/6a30a034cde879d7bfb15f95c99c9786)", I have "Ravenclaw" selected in my profile. I edited my profile to leave it blank, and the field disappeared but upon changing it to Ravenclaw again, it went to "Default" on the postbit.

MarkFL
07-24-2015, 03:18 PM
Okay, it sounds to me that the value being stored in the variable $post['field17'] isn't what you are expecting.

ProfC
07-24-2015, 03:43 PM
It seems it.

I'm not sure what I may have done wrong. This is a screenshot of the profile field from the ACP (https://www.dropbox.com/s/r6fruou83rr10hv/User%20Profile%20Field%20Manager%20-%20Kingdom%20of%20Alexandria%20-%20vBulletin%20Admin%20Control%20Panel%20%20%20htt p%20www%20alexandria-ns%20com%20admincp%20profilefield%20php%20do%3Dedi t%26profilefieldid%3D17.png?dl=0).

MarkFL
07-24-2015, 04:25 PM
Okay, try this as your plugin code:

if ($post['field17'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>House Membership</dt> <dd>' . $post['field17'] . '</dd>';
}

ProfC
07-24-2015, 05:45 PM
That works perfectly, thank you. :) It seems I was in fact using the wrong method. Now the question would be on how to get it to display a different image based on the option selected on your profile.

MarkFL
07-24-2015, 05:55 PM
Do your images have the options for field17 embedded in their URL? If so you could easily build the HTML using string concatenation. Suppose your images are stored in the folder "images/housemembership" and their filenames are composed of the options and the extension ".png". Then you would use the plugin code:

if ($post['field17'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>House Membership</dt> <dd><img src="images/housemembership/' . $post['field17'] . '.png" /></dd>';
}

ProfC
07-24-2015, 06:01 PM
They don't, but I'll work on that later tonight and see what I can whip up. Thank you ^^

MarkFL
07-24-2015, 06:04 PM
They don't, but I'll work on that later tonight and see what I can whip up. Thank you ^^

Rather than rename the folder and files, it would be easier to construct a switch statement to build the element. Just let me know the folder name and which image filename goes with which option, and I will write the plugin code. ;)

ProfC
07-24-2015, 06:43 PM
Rather than rename the folder and files, it would be easier to construct a switch statement to build the element. Just let me know the folder name and which image filename goes with which option, and I will write the plugin code. ;)

Thank you :)

I'll drop you a message in a few moments with everything.

akz645
08-30-2015, 12:32 AM
...
...

Multiple-Selection Menu
&
Multiple-Selection Checkbox

1) How do I get some/all of those fields highlighted/checkboxes ticked as the default during registration?

2) How do I force all my existing members into updating their user profile settings?
I have some forced options now (like gender). Members who are registering now are forced to pick male or female.
Whereas members who have already signed up, they aren't forced as nothing appears in their postbit (gender) unless they go to their userCP profile and press save.


P.S=
Thank you Lynne for this brilliant article :up:

Lynne
08-30-2015, 03:23 PM
1. For Multiple-Selection Menu, you may set the first one as default but that is the only option. There is no way to pre-select several checkboxes. I think you would need to write a plugin to do that.

2. I think you can set Field Required to Yes, Always and that should do what you want.

Yes, always - User will be required to complete this field at registration. Enabling this setting will force all users to complete it before they can continue using your forum. This applies only if the field is shown on the "Edit Your Details" page.

akz645
08-30-2015, 08:14 PM
1. For Multiple-Selection Menu, you may set the first one as default but that is the only option.
http://i.imgur.com/oBVhrlM.png + http://i.imgur.com/6h0gmLS.png
How do I set the first option as the default (highlighted)?
As the current settings I'm using, doesn't do this...

2. I think you can set Field Required to Yes, Always and that should do what you want.
"Yes, always - User will be required to complete this field at registration. Enabling this setting will force all users to complete it before they can continue using your forum. This applies only if the field is shown on the "Edit Your Details" page."
Cheers, that worked. (http://i.imgur.com/DUBuysJ.png)
Yes, at registration and profile updating - Doesn't work.
Yes, always - Worked :)

Lynne
08-31-2015, 02:29 PM
1) Whoops, sorry, I was looking at the wrong type of profile field (single-selection menu, not multi-selection menu).

akz645
08-31-2015, 09:48 PM
1) Whoops, sorry, I was looking at the wrong type of profile field (single-selection menu, not multi-selection menu).
Ah alright. Anyway, thanks for the help :)

https://vborg.vbsupport.ru/showthread.php?t=320081
I made a request for somebody to make a plugin allowing the admin to set defaults for Multiple-Selection Menu/Checkbox when creating a User Profile Field.

akz645
09-17-2015, 12:52 AM
...
...
1) Do you know any way to set it so only certain usergroups will have X User Profile Field option appear in their userCP?

2) How do I execute a SQL Query to force All Users/ Certain Usergroups/ Certain Users to have their X user profile field options changed into what I want?
They can change into what they want from the userCP later.

Lynne
09-17-2015, 03:17 PM
1) No, I do not.

2) Very hard to say without specifics. But, you can probably use phpMyAdmin to do it.

akz645
09-17-2015, 03:22 PM
2) Very hard to say without specifics. But, you can probably use phpMyAdmin to do it.

I was hoping it would be something straight forward like this:

Invisible
On: UPDATE user SET options=options + 512 WHERE NOT(options & 512);
Off: UPDATE user SET options=options - 512 WHERE options & 512;

Run from Execute SQL Query (http://i.imgur.com/vuSQ2ym.png)

Where you'd just need to colour code what I need to change depending on my options & field number.

Lynne
09-17-2015, 07:42 PM
It would be something like that only on the userfield table (where the settings for the user profile fields are kept). But, if it is for a certain usergroup, your WHERE statement would have to include a SELECT of only certain users whose user.usergroupid was xx since the usergroupid is not included in the userfield table. I'm not good at writing those sort of queries.

akz645
09-27-2015, 08:03 PM
How do I execute a SQL Query (http://i.imgur.com/EY4oMRF.png) to force All Users/ Certain Usergroups/ Certain Users to have their X user profile field options changed into what I want?
They can change into what they want from the userCP later.

Glenn Vergara (http://www.vbulletin.com/forum/member/326711-glenn-vergara) posted how to do it, from vbulletin.com (http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/4329490-execute-sql-query-how-do-i-change-custom-user-profile-field-options-for-multiple-usergroups-users) :)

1) UPDATE userfield SET field5='Hide' where userid in (SELECT userid FROM user WHERE usergroupid IN (X, X, X))
This code allows you to change a usergroups' custom user profile field (any option they have), to whatever specific option you want them all to have changed to.
Key:
Red = User Profile Field ID (https://vborg.vbsupport.ru/attachment.php?attachmentid=153271&d=1441250074).
Green = User Profile Field Option you want to change to (http://i.imgur.com/vIho695.png).
Blue = Usergroup ID (http://i.imgur.com/6aw8rr5.png).

2) UPDATE userfield SET field5='Hide' where field5='Male' AND userid in (SELECT userid FROM user WHERE usergroupid IN (X, X, X))
This code allows you to change a usergroups' custom user profile field (any single option), to whatever other specific option you want them all to have it changed to.
Key:
Red = User Profile Field ID (https://vborg.vbsupport.ru/attachment.php?attachmentid=153271&d=1441250074).
Green = User Profile Field Option you want to change to (http://i.imgur.com/yCn5P60.png).
Orange = Option you want changed (http://i.imgur.com/yCn5P60.png).
Blue = Usergroup ID (http://i.imgur.com/6aw8rr5.png).

3) UPDATE userfield SET field5='Hide' where (field5='Male' OR field5='Female') AND userid in (SELECT userid FROM user WHERE usergroupid IN (X, X, X))
This code allows you to change a usergroups' custom user profile field (multiple options), to whatever specific option you want them all to have it changed to. If they have selected an option you don't include (example: Other (http://i.imgur.com/qpmXCUw.png)), then users who have selected that option will be left unaffected.
Key:
Red = User Profile Field ID (https://vborg.vbsupport.ru/attachment.php?attachmentid=153271&d=1441250074).
Green = User Profile Field Option you want to change to (http://i.imgur.com/ICFIxBu.png).
Orange = Option you want changed (http://i.imgur.com/ICFIxBu.png).
Blue = Usergroup ID (http://i.imgur.com/6aw8rr5.png).

Note: Change usergroupid to userid to change for several users, instead of entire usergroups.
Note 2: You don't have to select more than 1 usergroup. Just selecting 1 usergroup still works.

P.S= If you want to know how to change 'Display Reputation', 'Invisible' etc, check out my guide here:
https://vborg.vbsupport.ru/showthread.php?p=2555258#post2555258

--------------- Added 1443391500 at 1443391500 ---------------

Do you know any way to set it so only certain usergroups will have X User Profile Field option appear in their userCP?
That's the only question still left unanswered.

If anybody can help out, that would be great :)

StormBreaker
05-09-2017, 11:10 AM
If i want to show profile field in ad_navbar_below template instead of {vb:var adsense_pub_id}.. I done this>>
google_ad_client = "{vb:var adsense_pub_id}";
to
google_ad_client = "{vb:raw post.field8}";

Will it work?

Lynne
05-09-2017, 08:11 PM
If i want to show profile field in ad_navbar_below template instead of {vb:var adsense_pub_id}.. I done this>>
google_ad_client = "{vb:var adsense_pub_id}";
to
google_ad_client = "{vb:raw post.field8}";

Will it work?
Doubtful. I do not believe the $post variable is registered for use in that template. And, most likely you want to use $vbuserinfo or something like that and so you would need to register that variable for use in that template.