Latest Register Log In

+ Advanced Search

Different Custom Fields Per Category

Different Custom Fields Per Category
02/23/13 (Edited 03/11/14)

Suppose you have two different types of submissions, so you want a different set of fields to appear when submitting in one category compared to another.

In WSN 9.0 or later:

Go to the field manager at Admin Panel -> Listings -> Listing Fields. When you add a new listing field or edit one of the existing ones here, find the "Bind to Categories" prompt and select the categories you want the field to appear in. If no categories are selected, the field will appear in every category.

In WSN 8.0 or earlier:

In older versions there are two approaches you can take to make the submit end edit listing templates appropriate to their categories:

(A) Create custom templates (At Admin -> Themes -> Manage Templates -> create custom template) that are copies of the submit listing and edit listing templates to be used for your second type of submissions, on which you remove unwanted fields and add any new wanted ones (you can cut and paste standard fields from the standard submit end edit listing templates, and custom fields from the "Listing Fields - Add/Edit" template which is where they'll have gone by default when they're added). Then go to the edit category page for the categories which will use the second type of submission and select the custom templates you made in the "Custom Templates" section where it asks for submit listing and edit listing templates.

The drawbacks of this method are that you have to maintain four submit and edit templates instead of two (still manageable but if you have 8 different types of submissions then your templates will be multiplying out of control), and that you have to edit each subcategory (if they're supposed to apply to all subcategories below a category) to assign the appropriate submit and edit custom templates because there's presently no option to inherit them automatically.

(B) Alternately, use single submit listing and edit listing templates with conditionals to distinguish the fields like this
put fields exclusive to category id #1 and its subcategories here

put fields exclusive to category id #2 and its subcategories here

You can find the category id number on the edit category page where it says "Edit Category #50 (Category Name)".

The drawback of this method is that you'll also have to prevent people from changing their category selection during the submission process, since if they changed the category they'd be looking at the wrong fields. To stop them changing the category, first replace this block from both the submit and edit listing templates (it may look different depending on whether you have an english-only install or a different theme, but it's always the category selection area):
<td class="labelscolumn"><span class="labels">{LANG_GENERAL_CATEGORY}:</span></td>
<td class="optionscolumn">

<div id="catlevels">
<div id="levelbox{LEVELID}" class="floatleft">
<select name="catlevelid[{LEVELID}]" size="5" onclick="wsn_getnextlevel(this.value)">{LEVELOPS}</select>
<!-- LEVELS ROWS -->
<div class="clear"></div>
<IF {SWITCH_CATSELECTOR}><select name="catid" required="required" class="required">{CATSELECTOR}</select><ELSE><input type="<IF {CATID}>hidden<ELSE>text</IF>" name="catid" value="{CATID}" >{CATNAME}</IF>
<br ><input type="checkbox" name="setnewcat" onclick="wsn_showorhide('div1');" value="1" {SUGNEWCATCHECK} > {LANG_SUGGESTLINK_SUGGESTCAT}
<div id="div1" style="position: relative;<IF not {SUGNEWCATCHECK}> display: none;</IF>">
<input type="text" name="suggestcatname" size="{STANDARDSIZE}" value="{SUGGESTCATNAME}" > {LANG_SUGGESTLINK_ASSUB}
<IF {SWITCH_CATSELECTOR}><select name="suggestcatparent"><option value="0">{LANG_TOPLEVEL}</option>{FUNC_CATSELECTOR[{SUGGESTCATPARENT}]}</select><ELSE><input type="text" name="suggestcatparent" value="{SUGGESTCATPARENT}" size="4" ></IF>

with this hidden input to force a category:

<input type="hidden" name="catid" value="{CATID}" >

Then edit the main index template to delete

so that they have to go into a category in order to submit to it.

Finally we come to the matter of how to display the listings differently. Using conditionals like in option B above is normally the best way here -- go to Admin -> Themes -> Manage Templates -> Listing Details (or combined details+comments if that switch is on) and just customize your display with conditionals that check

put display code exclusive to category id #2 and its subcategories here

For custom fields, you can cut and paste their display code out of the "Listing Fields - Display" template which they're automatically added to when you add the field.

At this point, your site should be displaying the two separate types of categories appropriately.

Description How to have different categories use different submission forms and different display results.
Views 548 views. Averaging 0 views per day.