Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 5 Connect Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[vB5] User Profile Fields in the postbit templates
Lynne's Avatar
Lynne
Join Date: Sep 2004
Posts: 41,180

 

California/Idaho
Show Printable Version Email this Page Subscription
Lynne Lynne is offline 04-09-2013, 10:00 PM

Using your User Profile Fields on your site

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.


First thing to do is figure out which fields you want to add to your postbit. Go to your Admincp > User Profile Fields > User Profile Field Manager and note both the Field Name (field1, field2, etc) and the Category the field is in (see image 1). The Profile Fields are listed under their Category Title on this page. It should either be "(Uncategorized)" or have some other category listed. To then get the Category ID, go to User Profile Field Categories, click to Edit the category you want the ID of, and it will be listed at the top - id x (see image 2). Uncategorized Categories have no Category ID.
Image 1:


Image 2:
So, now that you have a list of field ids and category ids, you can now easily add them to your postbit.

First make sure your hook system is active (it is turned off by default). Go to Admincp > Settings > Products/Hook System > Enable/Disable Hook System > Yes.

Now, go to Admincp > Products & Hooks > Manage Hooks and click the link that says "[Add New Hook]". In that new hook, set the following:
Hook is Active: Yes
Hook Location: conversation_userstats
Title: Show Profile Fields in Postbit
Template Name: conversation_fields
Hook Arguments: conversation=conversation
SAVE
Now go to Admincp > Styles & Templates > Style Manager > Add New Template and on that page, set the following:
Title: conversation_fields
Template:
Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}
For each field you want shown, you will need to add this code under that line:
Code:
<vb:if condition="$userInfo['fieldX']"><li><label>{vb:phrase fieldX_title}:</label> <span>{vb:raw userInfo.customFields.default.fieldX_title.val}</span></li></vb:if>
Replace the X in "FieldX" (three times) with the fieldid and, if your field is in a Category other than Uncategoried, then replace "default" with "categoryY_title" where Y is the category id.

So, for instance, say I have the following I want to add:
Name Category
field5 (uncategoried)
field7 New Cat(id 1)
Then my template would look like this:
Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}

<vb:if condition="$userInfo['field5']"><li><label>{vb:phrase field5_title}:</label> <span>{vb:raw userInfo.customFields.default.field5_title.val}</span></li></vb:if>

<vb:if condition="$userInfo['field7']"><li><label>{vb:phrase field7_title}:</label> <span>{vb:raw userInfo.customFields.category1_title.field7_title.val}</span}</li></vb:if>
That's it!

If running 5.1.0, there is a code fix to apply here.

Quote:
Originally Posted by Zachery
In the templates, after applying the following change to

core/vb/library/content/text.php

Find

PHP Code:
 if (!$canseehiddencustomfields)
{
// Get profile fields information
$fieldsInfo vB_Cache::instance(vB_Cache::CACHE_STD)->read('vBProfileFields');

if (empty(
$fieldsInfo))
{
$fieldsInfo $this->assertor->getRows('vBForum:profilefield');
vB_Cache::instance(vB_Cache::CACHE_STD)->write('vBProfileFields'$fieldsInfo1440, array('vBProfileFieldsChg'));
}

foreach (
$fieldsInfo as $field)
{
$fields['field' $field['profilefieldid']] = $field['hidden'];
}

Change it to:

PHP Code:
// Get profile fields information
$fieldsInfo vB_Cache::instance(vB_Cache::CACHE_STD)->read('vBProfileFields');
  if (empty(
$fieldsInfo))
{
$fieldsInfo $this->assertor->getRows('vBForum:profilefield');
vB_Cache::instance(vB_Cache::CACHE_STD)->write('vBProfileFields'$fieldsInfo1440, array('vBProfileFieldsChg'));
}
  foreach (
$fieldsInfo as $field)
{
$fields['field' $field['profilefieldid']] = $field['hidden'];

Attached Images
File Type: png UPF Categories.png (25.5 KB, 0 views)
File Type: png UPF Manager.png (62.7 KB, 0 views)
Reply With Quote
  #52  
Old 07-31-2014, 09:00 AM
Spangle Spangle is offline
 
Join Date: Jun 2011
Posts: 520
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm using 5.1.3 A6 and I still cannot get this to display the profile fields, here is the code I am using in the template conversation_fields

Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}

<vb:if condition="$userInfo['field5']"><li><label>{vb:phrase field5_title}:</label> <span>{vb:raw userInfo.customFields.default.field5_title.val}</span></li></vb:if>

<vb:if condition="$userInfo['field2']"><li><label>{vb:phrase field2_title}:</label> <span>{vb:raw userInfo.customFields.default.field2_title.val}</span></li></vb:if>
Reply With Quote
  #53  
Old 07-31-2014, 04:28 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just put your code into the template on my site and it works just fine.

If you are still getting the This is a Serious Error message on your page, then go into debug mode and see what the real error is.

To enable debug mode edit the /config.php file and change:

Code:
$config['debug'] = false;
To:
Code:
$config['debug'] = true;
Then edit the /core/includes/config.php file and change:

Code:
// $config['Misc']['debug'] = true;
To:
Code:
$config['Misc']['debug'] = true;
To set that up for only your IP address (replace xxx.xxx.xxx.xxx with your IP), put these lines around the code:

Code:
if($_SERVER['REMOTE_ADDR'] == "xxx.xxx.xxx.xxx") {
CODE HERE
}
Reply With Quote
  #54  
Old 08-10-2014, 02:16 AM
DisasterDotCom DisasterDotCom is offline
 
Join Date: Feb 2013
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How would I display a piece of information in the postbit only if the user VIEWING the page is logged in and in the supermoderator or admin user group?

--------------- Added [DATE]1407644438[/DATE] at [TIME]1407644438[/TIME] ---------------

Actually, I think I got it... but this could probably be cleaned up... I'm also not 100% sure membergroupids is an array? This is vb5.1.2

<vb:if condition="in_array($bbuserinfo[usergroupid], array(5,6,16))">
<vb:if condition="in_array($userInfo['membergroupids'], array(14,15))">
<span style="color:red;font-weight:bold;">Display Stuff Here</span><br>
</vb:if>
</vb:if>

--------------- Added [DATE]1407645650[/DATE] at [TIME]1407645650[/TIME] ---------------

And one more update... userinfo['membergroupids'] shows up as a string when I do a debugvardump. How do I check to see if it contains the group ID? vBulletin doesn't allow you to search in a string according to http://bit.ly/1uBdO1U
Reply With Quote
  #55  
Old 08-10-2014, 03:54 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I believe is_member_of is the function your would want to use.

<vb:if condition="is_member_of($bbuserinfo, 5, 6, 16)">
<vb:if condition="is_member_of($userInfo, 14, 15)">
Reply With Quote
  #56  
Old 09-03-2014, 03:11 AM
DesignMVD DesignMVD is offline
 
Join Date: Jul 2014
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the tutorial!

I show my result
Attached Images
File Type: png image_64273.png (43.5 KB, 0 views)
Reply With Quote
  #57  
Old 09-04-2014, 04:32 AM
vvlo vvlo is offline
 
Join Date: Sep 2011
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hi
I can not find Admincp > Styles & Templates > Style Manager > Add New Template
Instead There is : Add New style
And there is no place to add code
Reply With Quote
  #58  
Old 09-04-2014, 05:04 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add New Template is a dropdown next to the style. The default dropdown will say Style Variable Editor, so just click on that to see the other options.
Reply With Quote
  #59  
Old 09-04-2014, 06:05 PM
vvlo vvlo is offline
 
Join Date: Sep 2011
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Add New Template is a dropdown next to the style. The default dropdown will say Style Variable Editor, so just click on that to see the other options.
i use vBulletin Default Theme, and not see this option in dropdown.

dropdown option :edit setting
add child style
download
delete style

I added a child style and did change it and the problem was solved.
Thank you.
Reply With Quote
  #60  
Old 03-16-2015, 08:51 PM
raynestorm raynestorm is offline
 
Join Date: Mar 2015
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello--
I am following this tutorial and have created a new category called "Custom" and added a new field called "industry". "Industry" has several check boxes for the user to check. The "Custom" category has ID = 1 and the industry field is field=5. I created and added this code to a template called "conversation_fields":
PHP Code:
{vb:data userInfouserfetchProfileInfo, {vb:raw conversation.userid}}
<
vb:if condition="$userInfo['field5']"><li><label>{vb:phrase field5_title}:</label> <span>{vb:raw userInfo.customFields.category1_title.field5_title.val}</span></li></vb:if> 
The word "Industry: " displays in my postpit but the values (picked by checkbox) do not display. How can I get the value of the field "Industry" to also be displayed?

Thanks.
Reply With Quote
  #61  
Old 03-17-2015, 06:16 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That looks like it should work. Can I get a screen shot of your profile field 5?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05324 seconds
  • Memory Usage 2,369KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (9)bbcode_code
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (3)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete