1
etcetera
Calling custom fields in user profiles
  • 2009/7/6 20:23

  • etcetera

  • Just popping in

  • Posts: 23

  • Since: 2009/6/13


Hi there,

I was wondering, because I know nothing of PHP, if anyone would be kind enough to write code for me which will allow me to call custom user fields individually on the user profiles. I.e., if I want to add the fields "Gender" and "Age", I would like a command which will call and print only Gender or only Age for the user whose profile you are currently viewing.

The end result, to help you get a picture of what I am asking: I would like to create a new template for profiles which will embed all user fields in html, allowing me to set new CSS styles for certain fields, to take links saved as fields and make them appear as clickable links or as images, etc.

This request isn't imperative, but it would be very much appreciated.

Would anyone be so kind as to help me?

2
trabis
Re: Calling custom fields in user profiles
  • 2009/7/6 21:58

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Here is an example for displaying custom 'myfield' inside a system/templates/blocks/system_block_topusers.html.
<table cellspacing="1" class="outer">
  <{foreach 
item=user from=$block.users}>
  <
tr class="<{cycle values="even,odd"}>" valign="middle">
    <
td><{$user.rank}></td>
    <
td align="center">
      <{if 
$user.avatar != ""}>
      <
img src="<{$user.avatar}>" alt="" width="32" /><br />
      <{/if}>
      <
a href="<{$xoops_url}>/userinfo.php?uid=<{$user.id}>" title="<{$user.name}>"><{$user.name}></a>
      <
br />
      
      <{
php}>
      global 
$xoopsTpl;

      
$myField '';
      
$profile_handler =& xoops_getmodulehandler('profile''profile');
      
$profile $profile_handler->get($xoopsTpl->_tpl_vars['user']['id']);

      if (
is_object($profile)) {
        
$myField $profile->getVar('myfield');
      }
      
$xoopsTpl->assign('myField'$myField);
      <{/
php}>
      <{
$myField}>
      
    </
td>
    <
td align="center"><{$user.posts}></td>
  </
tr>
  <{/foreach}>
</
table>


Here is a simple example for echoing a custom 'myfield' from user 1 inside a php file:
$uid 1;
$myField '';
$profile_handler =& xoops_getmodulehandler('profile''profile');
$profile $profile_handler->get($uid);

if (
is_object($profile)) {
    
$myField $profile->getVar('myfield');
}
echo 
$myField;



3
etcetera
Re: Calling custom fields in user profiles
  • 2009/7/7 19:52

  • etcetera

  • Just popping in

  • Posts: 23

  • Since: 2009/6/13


I honestly know zero PHP. I attempted to use that first code, sans the <{foreach}>, and it did print the variable... but for the person viewing, not for the profile being viewed.

I'll keep poking at it, but since I'm fairly certain that call to the users block is pretty important and don't personally know how to reroute it for my needs... would it be too much to ask someone to alter this specifically for the user info template?

4
trabis
Re: Calling custom fields in user profiles
  • 2009/7/8 12:36

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


User info already displays user info. What am I missing?
CanĀ“t you choose to display "Gender" and "Age" on profile administration?

5
etcetera
Re: Calling custom fields in user profiles
  • 2009/7/8 15:26

  • etcetera

  • Just popping in

  • Posts: 23

  • Since: 2009/6/13


Take another look at my first post. I want to be able to call each variable individually so that I can have users insert a URL in certain fields and have that URL display as a clickable link or as an image, instead of just raw text.

6
trabis
Re: Calling custom fields in user profiles
  • 2009/7/8 17:24

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Got it, I think this will do it:
<{php}>
      global 
$xoopsTpl;

      
$myField '';
      
$profile_handler =& xoops_getmodulehandler('profile''profile');
      
$profile $profile_handler->get($xoopsTpl->_tpl_vars['user_uid']);

      if (
is_object($profile)) {
        
$myField $profile->getVar('myfield');
      }
      
$xoopsTpl->assign('myField'$myField);
      <{/
php}>
      <{
$myField}>

7
etcetera
Re: Calling custom fields in user profiles
  • 2009/7/8 19:21

  • etcetera

  • Just popping in

  • Posts: 23

  • Since: 2009/6/13


Thanks much! :)

8
Sir_Saeed
Re: Calling custom fields in user profiles
  • 2009/11/18 10:50

  • Sir_Saeed

  • Just popping in

  • Posts: 41

  • Since: 2007/10/10


How can it be possible to use such thing in theme?
Like as in this site which a permanent welcome message is always on the top of all pages, you just want to expand the welcome message with an extra information like home page, avatar, and so on.

I tested the codes in theme.html but it didn't work. Although it would be great if I can use these information in Forums poster information too.

Login

Who's Online

200 user(s) are online (135 user(s) are browsing Support Forums)


Members: 0


Guests: 200


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits