Dragonfly CMS v9 ⇒ CPG-BB (forum) :: Archives ⇒ Add user profile info to userinfo displayed in viewtopic :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum Index Modules & Blocks CPG-BB (forum) ⇒ Archives

Archived ⇒ Add user profile info to userinfo displayed in viewtopic


I am wanting, if possible, to display information from custom fields of user profiles in the author section of viewtopic in our website forums.

At the moment username, rank, avatar, joined, posts, and location are displayed.

I would like all of the above plus a custom field that I have created in user profiles to be displayed underneath Location.

Can anyone help or point me in the right direction to a topic already posted on this site (i've searched but can't find anything that exactly fits what I want).

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Debian GNU Linux/1.3.33/4.0.24/4.4.4/9.1.1


I'll just write it again since it might have changed with 9.1.1.

There are four parts.

1. Select what you need from the database.

First in line 291 of modules/forums/viewtopic.php we have:

$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.bio, u.user_timezone, u.user_occ, u.user_interests, p.*, pt.post_text, pt.post_subject";

You can add some more custom fields there for selection from the database. For example

$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.bio, u.user_timezone, u.user_occ, u.user_interests, u.therefcustomfield1, u.therefcustomfield2, p.*, pt.post_text, pt.post_subject";

2. Naming the variable is good, though it's possible to skip this step

Then, sometime after line 692 you can convert it from that array to a variable with its own name like:
$poster_tcf1 = $postrow[$i]['therefcustomfield1']; $poster_tcf2 = $postrow[$i]['therefcustomfield2'];

3. Assign it for reading by the theme.

Then around lines 1052-1110 we assign the variables that actually get passed to the theme for display. You can add lines like:
'POSTER_TCF1' => $poster_tcf1, 'POSTER_TCF2' => $poster_tcf2,

4. Add it to the theme.

Last thing is to actually add those into the theme. So in themes/yourtheme/template/forums/viewtopic_body.html (and you'll have to change this for each theme you have).

Add your placeholders wherever you want. Say you're using the default theme and you want them right under Join Date. Then line 79 of themes/default/template/forums/viewtopic_body.html would change from

<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}</span><br /></td>

To

<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_TCF1}<br />{postrow.POSTER_TCF2}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}</span><br /></td>

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


thanks very much

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Debian GNU Linux/1.3.33/4.0.24/4.4.4/9.1.1


I have searched through the site here and found no (working) answer to my issue. I want to include a variable for information from a custom field in the user account in forum posts...specifically right under the poster name. I tried one method found in a search and it didn't work. Another post I found was dated way back in 2004 and was not relevent.

Any help appreciated.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Apache/1.3.34 (Unix)/MySql 5.0.27-standard-log/PHP 5.1.6/DF 9.1.2.1


What was the method you tried, was it mine from a month ago?

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


Lol somebody merged it so fast I though I replied to the wrong topic. Razz

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


Yes, Sarah it was! Sorry, but I could not get it going. I am trying to add 1 custom field. I followed the directions above but nothing shows under poster name. I told some members that if they got their kudos up to a certain point they could create a "title" for themselves, and someone has gone and nearly met that goal! lol!

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Apache/1.3.34 (Unix)/MySql 5.0.27-standard-log/PHP 5.1.6/DF 9.1.2.1


What's the field you're trying to add, and I'll try to make it specific instead of the hypotheticals there.

Also are you using ForumsPro?

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


Trying to add a custom field called member_title. I am using regular forums that came with 9.0.6.1. Thanks.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Apache/1.3.34 (Unix)/MySql 5.0.27-standard-log/PHP 5.1.6/DF 9.1.2.1


Ok so step 1 you would add this both in line 290 and 292. Instead of

$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.server_specs, u.bio, u.user_timezone, u.user_occ, u.user_interests, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid"; } else { $sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.bio, u.user_timezone, u.user_occ, u.user_interests, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid";

You would have

$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.server_specs, u.bio, u.user_timezone, u.user_occ, u.user_interests, u.member_title, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid"; } else { $sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.bio, u.user_timezone, u.user_occ, u.user_interests, u.member_title, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid";

Then in this version, rows 1013-1070 are the ones that are going to offer up the user information for the theme to use. So anywhere in here, for example on line 1023 right after 'POSTER_AVATAR' => $poster_avatar, you can insert a new line and make it say:
'POSTER_MTITLE' => $postrow[$i]['member_title'],

Now open the template/forums/viewtopic_body.html (for every theme you have)

Then to add it right under their name change line 79 from

<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />

to

<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">[postrow.POSTER_MTITLE}<br />{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />

Clear site cache then refresh viewtopic.

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


Hi Sarah. Tried it, sorry still nothing. I had created a custom field called member_title and edited viewtopic.php and viewtopic_body.html, but I'm still not getting the title to show up in the forum posts. Hmmm...

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Apache/1.3.34 (Unix)/MySql 5.0.27-standard-log/PHP 5.1.6/DF 9.1.2.1


Anything in debugging? Can you turn on show queries and post the queries that viewtopic.php is generating?

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


I guess this is what you wanted to see...SQL debug from a test post I made.

SQL Queries:

index.php

* LINE 60: SELECT mid, title, custom_title, active, view, blocks, version FROM cms_modules WHERE LOWER(title)='forums'

modules/Forums/common.php

* LINE 87: SELECT * FROM cms_bbconfig

includes/phpBB/functions.php

* LINE 158: SELECT * FROM cms_bbthemes WHERE themes_id = 1
* LINE 326: SELECT word, replacement FROM cms_bbwords
* LINE 22: SELECT cat_id, cat_title FROM cms_bbcategories ORDER BY cat_order
* LINE 38: SELECT * FROM cms_bbforums ORDER BY cat_id, forum_order

modules/Forums/viewtopic.php

* LINE 126: SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_desc, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments, f.auth_download, t.topic_attachment, c.cat_title , COUNT(p2.post_id) AS prev_posts FROM cms_bbtopics t, cms_bbforums f, cms_bbcategories c , cms_bbposts p, cms_bbposts p2 WHERE p.post_id = 5172 AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= 5172 AND f.forum_id = t.forum_id AND f.cat_id = c.cat_id GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments, f.auth_download, t.topic_attachment ORDER BY p.post_id ASC
* LINE 168: SELECT notify_status FROM cms_bbtopics_watch WHERE topic_id = 1576 AND user_id = 2
* LINE 313: SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.member_title, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.bio, u.user_timezone, u.user_occ, u.user_interests, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid, u.kudos_pos-u.kudos_neg AS kudos FROM cms_bbposts p, cms_users u, cms_bbposts_text pt WHERE p.topic_id = 1576 AND pt.post_id = p.post_id AND u.user_id = p.poster_id ORDER BY p.post_time ASC LIMIT 0, 15
* LINE 347: SELECT * FROM cms_bbranks ORDER BY rank_special, rank_min
* LINE 734: UPDATE cms_bbtopics SET topic_views = topic_views + 1 WHERE topic_id = 1576
* LINE 737: SELECT prefix, dirname FROM cms_cpg_installs LIMIT 1
* LINE 888: SELECT COUNT(*) FROM cms_cpg_pictures AS p, cms_cpg_albums AS a WHERE a.aid=p.aid AND a.category=10002 LIMIT 0,1
* LINE 1036: SELECT s.uname, u.user_allow_viewonline FROM cms_session AS s LEFT JOIN cms_users AS u ON u.username=s.uname WHERE guest=0 OR guest=2 ORDER BY s.uname

includes/phpBB/auth.php

* LINE 169: SELECT a.forum_id, a.auth_view, a.auth_read, a.auth_post, a.auth_reply, a.auth_edit, a.auth_delete, a.auth_sticky, a.auth_announce, a.auth_vote, a.auth_pollcreate, a.auth_attachments, a.auth_download, a.auth_mod FROM cms_bbauth_access a, cms_bbuser_group ug WHERE ug.user_id = 2 AND ug.user_pending = 0 AND a.group_id = ug.group_id AND a.forum_id = 38

includes/functions/display.php

* LINE 318: SELECT * FROM cms_banner WHERE type='0' AND active='1' ORDER BY RAND() LIMIT 0,1

includes/counter.php

* LINE 76: UPDATE cms_counter SET count=count+1 WHERE (var='Firefox' AND type='browser') OR (var='Windows' AND type='os')
* LINE 77: UPDATE cms_stats_hour SET hits=hits+1 WHERE (year='2007') AND (month='03') AND (date='01') AND (hour='18')

includes/nbbcode.php

* LINE 260: SELECT * FROM cms_bbsmilies

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Apache/1.3.34 (Unix)/MySql 5.0.27-standard-log/PHP 5.1.6/DF 9.1.2.1


It's selecting the field in the query so at least the first part is correct.

Question: After you edited the template did at least the extra line break between username and rank appear?

Diagon Alley - Top Design

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21-standard/4.4.4/9.1.1


Hey Sarah. No line break at all. Here is the code from viewtopic_body.html:

<span class="name1"> <center>{postrow.POSTER_NAME}<br />{postrow.POSTER_MTITLE}</center></span><hr /> <span class="postdetails"> <center>{postrow.RANK_IMAGE}</center><br /><center>{postrow.POSTER_AVATAR}</center> <center><br />{postrow.PROFILE_IMG} {postrow.PM_IMG} {postrow.EMAIL_IMG} {postrow.WWW_IMG} {postrow.GAL_IMG}<hr />{postrow.AIM_IMG} {postrow.YIM_IMG} {postrow.MSN_IMG} {postrow.ICQ_IMG}<hr /> {postrow.POSTER_ONLINE}</span><hr />{postrow.POSTER_POSTS}<hr>

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Apache/1.3.34 (Unix)/MySql 5.0.27-standard-log/PHP 5.1.6/DF 9.1.2.1

All times are UTC