# nats\_list\_linkcodes

*Article Topics:* [*Smarty*](https://docs.toomuchmedia.com/getting-started/common-topics/smarty)*,* [*Customization*](https://docs.toomuchmedia.com/getting-started/common-topics/customization)

To create a single linkcode, please see the [nats\_encode](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_encode) article.

## Parameters

(*Required parameters in **bold**)*

| Parameter                                                                                                                                 | Description                                                                                                                                                                                                                               | Possible Values                              | Default Value                                                   | Example                    |
| ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | --------------------------------------------------------------- | -------------------------- |
| tpl                                                                                                                                       | Template used to display output                                                                                                                                                                                                           | Any valid template                           | The template, *function\_list\_linkcodes*                       | tpl="mytemplate"           |
| code\_only                                                                                                                                | Displays the linkcode as either a complete or relative URL                                                                                                                                                                                | 0 or 1 (exclusive)                           | 0: displays entire URL                                          | code\_only="1"             |
| campaigns                                                                                                                                 | Return only linkcodes available to a list of [campaigns](https://docs.toomuchmedia.com/additional-resources/common-terms#campaign). **If set, ignores&#x20;*****campaign*****&#x20;and&#x20;*****use\_default\_campaign*****&#x20;below** | An array reference (see Notes section below) | *None.*                                                         | campaigns="$my\_array"     |
| campaign                                                                                                                                  | Return only linkcodes available to a single campaign. **If set, ignores&#x20;*****use\_default\_campaign*****&#x20;below**                                                                                                                | Any valid campaign number                    | The user's current default campaign                             | campaign="123"             |
| use\_default\_campaign                                                                                                                    | Return only linkcodes available to the database's stored default campaign for the current user. (See notes for arguments, *campaign* and *campaigns*, above)                                                                              | 0 or 1 (exclusive)                           | *None.*                                                         | use\_default\_campaign="1" |
| userid                                                                                                                                    | The user ID number to get the default campaign from                                                                                                                                                                                       | Any valid user ID number                     | The currently logged in user.                                   | userid="123"               |
| programs                                                                                                                                  | Return only linkcodes available to a list of programs **If set, ignores&#x20;*****program*****&#x20;below**                                                                                                                               | An array reference (see Notes section below) | *None.*                                                         | programs="$my\_array"      |
| program                                                                                                                                   | Returns only linkcodes available to a single program. **If set, ignores&#x20;*****use\_default\_program*****&#x20;below**                                                                                                                 | Any valid program ID number                  | The user's default program                                      | program="123"              |
| use\_default\_program                                                                                                                     | Returns only linkcodes available to the database's stored default program for the current user. (See notes for arguments, *program* and *programs*, above)                                                                                | 0 or 1 (exclusive)                           | *None.* The default in program will apply (see *program* above) | use\_default\_campaign="1" |
| sites                                                                                                                                     | Return only linkcodes available to a list of sites. **If set, ignores&#x20;*****site*****&#x20;and&#x20;*****use\_default\_site*****&#x20;below**                                                                                         | An array reference (see Notes section below) | *None.*                                                         | sites="$my\_array"         |
| site                                                                                                                                      | Return only linkcodes available to a particular site. **If set, ignores&#x20;*****use\_default\_site*****&#x20;below**                                                                                                                    | Any valid site ID number                     | The user's default site                                         | site="123"                 |
| use\_default\_site                                                                                                                        | Returns only linkcodes available to the database's stored default site for current user. (See notes for arguments *site* and *sites*, above)                                                                                              | 0 or 1 (exclusive)                           | *None.* The default site will apply (see *site* above)          | use\_default\_site="1"     |
| tour                                                                                                                                      | Return only linkcodes available to a particular tour. (See note in *tours* below)                                                                                                                                                         | Any valid tour ID number                     | All tours unless *tours*, below, is used                        | tour="123"                 |
| tours                                                                                                                                     | Return only linkcodes available to a list of tours. **If set, overwrites&#x20;*****tour*****&#x20;above**                                                                                                                                 | An array reference (see Notes section below) | All tours unless *tour*, above, is used                         | tours="$my\_array"         |
| adtool                                                                                                                                    | Return only linkcodes available to a particular [adtool](https://docs.toomuchmedia.com/additional-resources/common-terms#ad-tool). (See note in *adtools* below)                                                                          | Any valid adtool ID number                   | All adtools unless *adtools*, below, is used                    | adtool="123"               |
| adtools                                                                                                                                   | Return only linkcodes available to a list of adtools. **If set, overwrites&#x20;*****adtool*****&#x20;above**                                                                                                                             | An array reference (see Notes section below) | All adtools unless *adtool*, above, is used                     | adtools="$my\_array"       |
| subid1                                                                                                                                    | Return only linkcodes available to a particular first subid (See note in *subids1* below)                                                                                                                                                 | Any valid first sub ID number                | All first subids unless *subids1*, below, is used               | subid1="123"               |
| subids1                                                                                                                                   | Return only linkcodes available to a list of first subids **If set, overwrites&#x20;*****subid1*****&#x20;above**                                                                                                                         | An array reference (see Notes section below) | All subids unless *subid1*, above, is used                      | subids1="$my\_array"       |
| subid2                                                                                                                                    | Return only linkcodes available to a particular second subid. (See note in *subids2* below)                                                                                                                                               | Any valid second sub ID number               | All second subids unless *subid2*, below, is used               | subid2="123"               |
| subids2                                                                                                                                   | Return only linkcodes available to a list of second subids. **If set, overwrites&#x20;*****subid2*****&#x20;above**                                                                                                                       | An array reference (see Notes section below) | All second subids unless *subid2*, above, is used               | subids2="$my\_array"       |
| count                                                                                                                                     | Max number of linkcodes to display                                                                                                                                                                                                        | Any whole number greater than zero           | *None.* Displays all matching linkcodes                         | count="10"                 |
| [assign\_prefix](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-function-parameters/assign_prefix) | Prefix output variables with this word. (Click link for details)                                                                                                                                                                          | Any valid Smarty variable name               | *None.* (No prefix is used)                                     | assign\_prefix="myvar"     |
| [data\_only](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-function-parameters/data_only)         | Set variables but don't display the template                                                                                                                                                                                              | 1                                            | *None.* The template is displayed.                              | data\_only=1               |
| show\_hidden                                                                                                                              | Show link codes for hidden sites.                                                                                                                                                                                                         | 0 or 1 (exclusive)                           | *None.* Do not show hidden sites                                | show\_hidden="1"           |
| order                                                                                                                                     | Change the ordering of the link codes returned by the template function                                                                                                                                                                   | (see Notes section below)                    | s.name, t.name                                                  | order="s.name, t.name"     |

## Output

By default, displays a list of link codes using the template *function\_list\_linkcodes.* and places the linkcodes in the *{$linkcodes}* array. The linkcodes array contains six associatives:

1. program I.D.
2. site I.D.
3. tour I.D.
4. adtool I.D.
5. sub I.D #1
6. sub I.D. #2

Each linkcode will always have a program I.D., site I.D., and tour I.D.; they may have adtool and sub I.D.s. For example, the following variable contains the linkcode for the program one, site two, and tour three:

```
{$linkcodes.1.2.3.0.0.0}
```

## Examples

### Listing Linkcodes in an Email

Each [affiliate](https://docs.toomuchmedia.com/additional-resources/common-terms#affiliate)[#affiliate](https://docs.toomuchmedia.com/additional-resources/common-terms#affiliate "mention") that receives an email with the following function call will get their linkcodes for the program and site you specify.

```
{nats_list_linkcodes userid=$loginid data_only=1 program=program_number site=site_number}
```

Replace *program\_number* with the program [I.D. number](https://docs.toomuchmedia.com/using-nats/nats-admin-features/id-numbers). Replace *site\_number* with the site I.D. number.

### Inserting the natscode in an Emailed Tour Link

Each affiliate that receives an email with the following text and Smarty code will get the link to the tour with their [natscode](https://docs.toomuchmedia.com/additional-resources/common-terms#natscode) embedded in the URL:

```
URL?nats={nats_list_linkcodes userid=$toid program=program_number site=site_number 
  tour=tour_number data_only=1 code_only=1}{$linkcodes.program_number.site_number.tour_number.0.0.0}
```

Replace URL with the URL to the tour. Replace *program\_number* with the program [I.D. number](https://docs.toomuchmedia.com/using-nats/nats-admin-features/id-numbers). Replace *site\_number* with the site [I.D. number](https://docs.toomuchmedia.com/using-nats/nats-admin-features/id-numbers). Replace tour\_number with the tour I.D. number. For a tour on *example.com/tour,* program number one, site number two, and tour number three, the code looks like:

```
http://example.com/tour?nats={nats_list_linkcodes userid=$toid program=1 site=2 tour=3 data_only=1 code_only=1}{$linkcodes.1.2.3.0.0.0}
```

## Notes

{% hint style="info" %}
**Please Note:** If you are looking to add a NATS code to Ad Tool links in an e-mail then we recommend using the [nats\_encode](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_encode) template function.
{% endhint %}

(To create a single linkcode, please see the [nats\_encode ](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_encode)page.)

To make an array reference, create the array using the [nats\_add\_to\_array](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_add_to_array) function.

You can order the link codes by site, tour and program. You can select which fields you wish to order by based on the columns available within the database table. To order by a column within the site table, you must prefix the column with 's.' (Example: order="s.siteid"). To order by the tour table, you must prefix the column with 't.' and the program table by 'p.'.

## See Also

* [nats\_list\_campaigns](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_list_campaigns)
* [nats\_list\_sites](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_list_sites)
* [nats\_list\_tours](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_list_tours)
* [nats\_list\_xsells](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_list_xsells)

## **Related Articles**

{% content-ref url="nats\_encode" %}
[nats\_encode](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_encode)
{% endcontent-ref %}
