Adding Custom Thread Fields Text to Forum Pages

Cameron

New Member
Joined
May 10, 2021
Messages
11
Reaction score
0
Points
1
  • #1
I run a very geographically based XenForo forum and way back in the beginning, I set up some custom thread fields that each person who creates a new thread would have to fill in. These thread fields were and still are required. What are the fields? They are city, state, and zip code. So basically, when someone creates a new thread, they'll also need to fill in the City, State, and Zip fields that describe where they live.

I got to thinking and I have decided that I would like to add the data from these custom fields to the thread listings on the forum pages. I saw this on another XenForo site and liked it, so I want to do it myself. This is what it would look like:

xenforo-custom-thread-fields-forum-pages.gif

The location data would show under each and every thread link on all of the forum pages. My question is, does anyone know how to add custom thread field data to the thread list on a forum page in XenForo?
 

JodyBuchanan

New Member
Joined
May 10, 2021
Messages
11
Reaction score
0
Points
1
  • #2
This is possible and it's not difficult at all to add the custom thread fields to the thread lists on the forum pages. You'll add your code to the thread_list_macros template in the ACP.

The code will need to be inserted at line 183 (currently). Depending on what your Field IDs look like, your code will look something like this:

Code:
<!-- ADD CUSTOM FIELDS TO THREAD LIST ON FORUM PAGES -->                       
<xf:if is="{$thread.custom_fields.City}">
<span>&#183;</span> {$thread.custom_fields.City},
</xf:if>
<xf:if is="{$thread.custom_fields.LocationState}">
{$thread.custom_fields.getFormattedValue('LocationState')}
</xf:if>
<xf:if is="{$thread.custom_fields.LocationZip}">
{$thread.custom_fields.LocationZip}
</xf:if>                       
<!-- ADD CUSTOM FIELDS TO THREAD LIST ON FORUM PAGES -->

As you can see, I took the liberty of naming the Field IDs City, LocationState, and LocationZip. You would need to change those variables to what your names are. Let me know if this helps.
 
Adding Custom Thread Fields Text to Forum Pages was posted on 06-13-2021 by Cameron in the XenForo forum.

Similar threads

Forum statistics

Threads
88
Messages
156
Members
17
Latest member
mandy cromarty
Top