How to post user info + user custom fields on a page

tajhay

Well-known member
Hi,
I have a sports forum. I have created players as members, complete with their pic as avatar, height/weight as custom fields etc.

Now i want to output that info on a page. So basically I will create a page for each player.

I can create the html template for the page, and want to know how to query the user so i can get info from their member pages. Can anyone assist?
 
That requires PHP code. In the case of a page node you can use a callback function. I can help with the code, but this seems redundant with the existing profile pages which already show all of a user's information. Is there a reason you aren't using profile pages?
 
That requires PHP code. In the case of a page node you can use a callback function. I can help with the code, but this seems redundant with the existing profile pages which already show all of a user's information. Is there a reason you aren't using profile pages?
Hi Jake, Reason why im not using profile pages are that it lists player names after you click them. Ontop of that i will need to edit the template to hide other fields like posting on their profile etc. Dont want that.

I am simply trying to capture player info and put them against these dummy members. Instead of using another database i want to be able to use xenforo features and i feel custom fields will allow me a lot of flexibility in what i can do. For example in one page i want to have a green field, and the players avatars with perhaps just their name listed underneath it. I can create such page in html. when clicking on the player names or avatar it should bring out this page that i am requesting here where it shows players avatar, custom fields etc, that i am able to position anywhere on that page, so for example it could look like a wikipedia page of a sports player.

Your help would be greatly appreciated mate
 
I have attached a callback function you can use for your page node. Upload the PageNode.php file to library/Callback (create that directory). You need to specify the userid in that file:

Rich (BB code):
<?php

class Callback_PageNode
{
	public static function getUser(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
	{
		$userId = 1;

		$userModel = XenForo_Model::create('XenForo_Model_User');
		$user = $userModel->getFullUserById($userId);
		$user = $userModel->prepareUser($user);

		$response->params['user'] = $user;
	}
}

Then specify that callback for your page node:

Screen shot 2012-07-12 at 10.46.49 PM.webp

Now you can access the $user variable in the template for your page node. This gives you access to the avatar and customFields:

Screen shot 2012-07-12 at 10.47.20 PM.webp

Code:
{$user.customFields.business_directory}

<xen:avatar user="$user" size="m" />
 

Attachments

Thanks, I will have a few different members (around 20) that I will be creating a page for, so i have to have ~20 instances of that file? Is there an easy way to make it more configurable..id using the xencode in the template html to determine which user to get the info from?
 
Use this to read in the user_id from the URL:

Rich (BB code):
<?php

class Callback_PageNode
{
	public static function getUser(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
	{
		$userId = $controller->getInput()->filterSingle('u', XenForo_Input::UINT);

		$userModel = XenForo_Model::create('XenForo_Model_User');
		$user = $userModel->getFullUserById($userId);
		$user = $userModel->prepareUser($user);

		$response->params['user'] = $user;
	}
}

Now you pass the user_id via the URL like this:

http://www.yoursite.com/pages/mypage/?u=1
 
I think this may be part what I am after..

I want to allow my members to vote on player ratings for matches.
On the new page I want to list the matches and when clicked go to an data capture form where ratings can be entered for each player.

These ratings would then be written - along with some user details - to a new table in my database.

Combined results from all users would then be displayed on the site...

Will this code above allow me to get started with this?
 
ok.. and what i must wrote, if i need the first Thread (the newest) from here as full text and the next 5 threads shorten in the node? An that must work automatic :)

And is that a problem for SEO?
 
Where would this code go? within the pagenode.php? I have a custom field called 'referral" and i would like it captured in my db at the least.

Use this to read in the user_id from the URL:

Rich (BB code):
<?php

class Callback_PageNode
{
    public static function getUser(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        $userId = $controller->getInput()->filterSingle('u', XenForo_Input::UINT);

        $userModel = XenForo_Model::create('XenForo_Model_User');
        $user = $userModel->getFullUserById($userId);
        $user = $userModel->prepareUser($user);

        $response->params['user'] = $user;
    }
}

Now you pass the user_id via the URL like this:

http://www.yoursite.com/pages/mypage/?u=1
Use this to read in the user_id from the URL:

Rich (BB code):
<?php

class Callback_PageNode
{
    public static function getUser(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        $userId = $controller->getInput()->filterSingle('u', XenForo_Input::UINT);

        $userModel = XenForo_Model::create('XenForo_Model_User');
        $user = $userModel->getFullUserById($userId);
        $user = $userModel->prepareUser($user);

        $response->params['user'] = $user;
    }
}

Now you pass the user_id via the URL like this:

http://www.yoursite.com/pages/mypage/?u=1
 
Top Bottom