Latest Register Log In

+ Advanced Search

Different Custom Fields Per Category

Different Custom Fields Per Category
By
Feb 23, 2013 (Edited Mar 11, 2014)

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 -> Link 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
<IF {CATISBENEATH[1]}>
put fields exclusive to category id #1 and its subcategories here
</IF>

<IF {CATISBENEATH[2]}>
put fields exclusive to category id #2 and its subcategories here
</IF>

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):
<tr>
<td class="labelscolumn"><span class="labels">{LANG_GENERAL_CATEGORY}:</span></td>
<td class="optionscolumn">

<IF {SWITCH_LEVELSELECTOR}>
<div id="catlevels">
<div id="levelbox{LEVELID}" class="floatleft">
<select name="catlevelid[{LEVELID}]" size="5" onclick="wsn_getnextlevel(this.value)">{LEVELOPS}</select>
</div>
<!-- LEVELS ROWS -->
<div class="clear"></div>
</div>
<OTHERWISE>
<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>
</IF>
<IF {THISMEMBERGROUPCANSUBMITCATEGORIES}>
<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>
</div>
</IF>
</td>
</tr>


with this hidden input to force a category:

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

Then edit the main index template to delete
<IF {THISMEMBERGROUPCANSUBMITLINKS} or {SWITCH_DENIALPAGE}><li> <a href="suggest.php?action=addlink">{LANG_TITLE_SUGGESTNEWLINK}</a></li></IF>

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 -> Link Details (or combined details+comments if that switch is on) and just customize your display with conditionals that check

<IF {CATISBENEATH[2]}>
put display code exclusive to category id #2 and its subcategories here
</IF>


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.
Rating
Views 552 views. Averaging 0 views per day.
Similar Listings