WSN Knowledge Base https://scripts.webmastersite.net/wsnkb/manual en-us Different Custom Fields Per Category How to have different categories use different submission forms and different display results. https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/different-custom-fields-per-category-585.html Sun, 24 Feb 2013 04:32:21 GMT https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/different-custom-fields-per-category-585.html
In WSN 9.0 or later:

Go to the field manager at Admin Panel -> Articles -> Article Fields. When you add a new article 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 article templates appropriate to their categories:

(A) Create custom templates (At Admin -> Themes -> Manage Templates -> create custom template) that are copies of the submit article and edit article 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 article templates, and custom fields from the "Article 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 article and edit article 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 article and edit article 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 article 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 articles differently. Using conditionals like in option B above is normally the best way here -- go to Admin -> Themes -> Manage Templates -> Article 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 "Article 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.]]>
Custom WYSIWYG Fields Use WYSIWYG editors for custom fields. https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/custom-wysiwyg-fields-503.html Sat, 20 Jun 2009 11:38:41 GMT https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/custom-wysiwyg-fields-503.html
1. At Admin -> Settings -> Tweaks Editor, place your custom field name in the extrawysifields tweak. If you have multiple, separate with commas.
2a. If it's a article field and you're running WSN 9 or later, go to Admin -> Articles -> Article Fields and use this code in the display html area when adding/editing the field: <textarea name="yourfieldname" id="yourfieldname" class="submitdescription">{LINKEDITORCONTENT[yourfieldname]}</textarea>
2b. If it's not a article field, or you're using WSN 8 or older, use this code in the submit/edit template:
<tr>
<td class="labelscolumn"><span class="labels">Your Custom Field:</span>
<p class="center"><select name="editormode">{EDITORMODEOPS}</select></p>
</td>
<td class="optionscolumn">
<textarea name="yourfieldname" id="yourfieldname" class="submitdescription">{LINKEDITORCONTENT[yourfieldname]}</textarea>
</td>
</tr>
]]>
Adding a New Field Tracking new data. https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/adding-a-new-field-98.html Mon, 10 Nov 2003 20:34:13 GMT https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/adding-a-new-field-98.html
Article Fields in WSN 9.0+

As of WSN 9.0, you can use the field manager utility at Admin Panel -> Articles -> Article Fields to add and edit article fields. This utility makes everything easy for you while providing complete control.

Other Fields and Older Versions

Go to Admin Panel -> Customizations -> Add Fields to get started.

For example purposes, suppose you want article submitters to be able to specify a color for the article they're submitting. Choose 'article field' and type a suitable label such as 'color' (please note that the field name has to be alphanumeric, no spaces or accented characters -- keep it short and simple). Next, select the desired way to collect the input from the user -- a simple input box, a dropdown selector, checkboxes or the like. The simplest method is a regular input box, that's what you usually want. If the content will be a large amount of text (perhaps an article), you will want to choose the 'text area' option. If you wish to display options to let the submitter check a box for each one that applies to their article, use checkboxes. If you want to let them choose a single option from a dropdown menu (like the category selector in the top right of your screen now), then choose 'dropdown selector'. If you want a combo box that allows multiple selections (like your 'related categories' options on the edit category page), choose 'multiselect combo box'. To list several options in the same style as checkboxes but only allow the submitter to choose exactly one option (no more, no less), choose 'radio button'. If this field is not something that you want to be selectable or editable by anyone (even yourself), you may wish to make it invisible.

For our color field, we'll likely want these selections:
[image]addfields.jpg[/image]
Note that we've filled in the list of colors in the box that appears for that when we choose to make it a dropdown selector. Make sure you do a comma-separated list.

Next we come to a series of self-explanatory checkboxes which you normally want to leave checked, unless you don't want non-admins to submit or edit or you don't want the field's contents displayed or you don't want people to be able to search the field. We're ready to press the Add Field button now.

Now that the field has been added, you may want to edit the appearance of it. At Admin Panel -> Themes -> Manage Templates you'll find a "Custom Fields" section where all the custom fields code gets inserted by default. For the article color field we just added, click the "Add/Edit" next to Article Fields. You'll see the table row there which prompts people to choose the color and you can make any changes you want there. Sometimes, however, you want to control exactly where on the page the field appears -- you can do that by cutting and pasting from here to both the "Submit Article" and "Edit Article" templates at the desired location.

You can also change how the value in the field is displayed on the article details page, or make it be displayed in other templates like the article bit. First click the "Display" next to "Article Fields" on the Manage Templates Page. Cut and paste the display code for your field from there to your desired location in the "Article Details" template (or "Combined Details + Comments" if that switch is on). You can also copy it to any other template where article variables are applicable. You may want to use template conditionals to control the display.

For types of fields other than article fields, there's no autogenerated display code. Instead, you'll have to write your own using the template variable it gives you when you make the field... that'll be { + TYPE + FIELDNAME + }, for example {CATSPECIAL} for a category field named special. For a category field, you'll probably want to show it in the main index template. For a member field, the view profile template.

Selectors and Checkboxes Notes

If you're dealing with a single checkbox or single selector and want to test if a value is selected, you can use {LINKCHECKED[fieldname]} (or {CAT, {MEMBER etc) in your template conditional. If dealing with multi-value checkboxes or selectors, you can use {LINKCHECKED[fieldname <,> value]}> to test for each value. If you just want a comma-separated list of all selected values, use {LINKSELECTIONSLIST[fieldname]}. Don't use the plain {LINKFIELDNAME} template variable as it will not produce the expected results for a mutli-value field.

Advanced Notes

If you add a custom setting, as of 7.1 it will go to the "custom settings" template in the admin cp templates. A new "custom settings" option will appear in your admin panel left frame menu at the bottom of the settings section.]]>
Custom Rating Fields Letting people vote on more specific details. https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/custom-rating-fields-32.html Thu, 25 Sep 2003 14:45:47 GMT https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/custom-rating-fields-32.html
A custom rating field can be added in the same way as any other new article field (go to Admin Panel -> Articles -> Article Fields in WSN 9.0+, or Admin Panel -> Customizations -> Add Fields in earlier versions), the only difference in the process being that you must give the template variable a name that includes 'rating' in it. For example, 'stylerating'. If you select rating field and don't include rating in the field name, it'll be appended automatically.

In the display html, you will need to make use of these separate article template variables for your new rating field:

{LINKSTARS[fieldname]} - Graphically displays the current rating with stars and allows voting by clicking a star.
{LINKRATING[fieldname]} - Shows the rating, which is a decimal number normally between 1 and 5 (depending on your min and max vote value settings).
{LINKVOTES[fieldname]} - Shows the number of votes so far.

Using the example of a field stylerating, you will have {LINKSTARS[stylerating]}, {LINKRATING[stylerating]} and {LINKVOTES[stylerating]}.

In the vote template you'll probably want to use {LINKSTARS[stylerating <,> own]} instead to show only the current viewer's vote (indicating to them what their vote was, and allowing them to change it if applicable).

To make showing/editing of individual votes work for custom rating fields, pass &field=ratingfieldname at the end of the normal show votes url.

To do custom ratings for members, use memid={MEMBERID} in place of id={LINKID} in your form.

If using the rating comments switch:

Those of you including comments with ratings will probably will need to make some further modifications to the Admin -> Themes -> Manage Templates -> "Vote" template. To collect the vote in the rating submission form, use this:
<tr>
<td class="labelscolumn"><span class="labels">Rate {LINKTITLE}'s Style:</span></td>
<td class="optionscolumn"><select name="styleratingvotevalue"><option value=""></option>{RATINGVOTEOPS[stylerating]}</select></td>
</tr>

To display a person's full set of ratings plus their comment in one spot. The toplist in the default "vote" template does this for you, but it doesn't include your custom rating fields. Then to display the vote above the comment after submitted, find
<div class="ratingsstars">
{RATINGSTARS}
</div>
and change it to
<div class="ratingsstars">
Overall rating: {RATINGSTARS}
<br>Style rating: {RATINGSTARS[stylerating]}
</div>
]]>
Removing and Renaming Taking out fields you don't want. https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/removing-and-renaming-33.html Thu, 25 Sep 2003 06:46:10 GMT https://scripts.webmastersite.net/wsnkb/manual/extending/adding-fields/removing-and-renaming-33.html
If it's a article field in WSN 9.0+, you can edit or remove it via Admin Panel -> Articles -> Article Fields. Otherwise, if you're absolutely certain that the field isn't being used anywhere, you can remove it through Admin Panel -> Customizations -> Add Fields by clicking the "Show/hide advanced options" link. Note that removing a field via the add fields page (unlike the Article Fields page) may not remove all of the associated HTML from your templates unless the code is nearly unchanged from the default... you may thus have to manually edit your templates to remove stuff.

If you rename a field, be certain that you edit all templates to use the new name of the field and the new template variable for it. You may wish to use the Admin Panel -> Miscellaneous -> Advanced Options page to do a bulk replace of all instances of the old field name and template variable in all templates with the new name and template variable of the field. In doing this be sure to replace both the field itself and the associated template variable -- in you rename field1 to field2, you must mass-replace field1 with field2 AND mass replace {LINKFIELD1} with {LINKFIELD2}.]]>