=== Content Switcher ===
Contributor: Kleor
Tags: cookie, content, env, get, google, multiple, number, optimizer, post, random, server, session, shortcode, switch, switcher, variable
Requires at least: 2.5
Tested up to: 3.0
Stable tag: 1.2
Easily display a random number, a random or variable content on your website. Optimize your website with Google Optimizer.
== Description ==
Content Switcher allows you to easily insert into posts, pages and widgets of your website random numbers, and random or variable contents. You can use it, for example, to display [COOKIE, ENV, GET, POST, SERVER or SESSION](http://www.php.net/manual/en/reserved.variables.php) variables. Content Switcher also allows you to optimize your website with Google Optimizer.
Complete Documentation:
- [in English](http://www.kleor-editions.com/content-switcher/en)
- [in French](http://www.kleor-editions.com/content-switcher)
= Random Numbers =
To display a random number between 0 and M, insert into your posts/pages/widgets a code like this:
`[random-number max=M]`
Example (random number between 0 and 5):
`[random-number max=5]`
To display a random number between m and M (m and M relative integers), insert into your posts/pages/widgets a code like this:
`[random-number min=m max=M]`
Example (random number between -3 and 8):
`[random-number min=-3 max=8]`
To display a random number belonging to a set, insert into your posts/pages/widgets a code like this:
`[random-number set=a/b/c/...]`
Example (random number belonging to { 34; 5; -3; 8; -21 }):
`[random-number set=34/5/-3/8/-21]`
You can use the "digits" attribute to display a random number with at least d digits:
`[random-number min=m max=M digits=d]`
Example (random number between 0 and 144, displayed with at least 3 digits):
`[random-number max=144 digits=3]`
Other example (random image taken from the short film Big Buck Bunny):
`
`
= Random Contents =
To display a random content, insert into your posts/pages/widgets a code like this:
`[random-content]
First random content[other]
Second random content[other]
Third random content[other]
...
[/random-content]`
Example:
`[random-content]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/random-content]`
It's possible to display several times the same (random or not random) string of characters, using the "string" attribute. You can specify any string of characters for this attribute, including shortcodes, provided to replace "[" by "(" and "]" by ")". And don't forget to include the quotes at the beginning and the end of the string:
`[random-content string="(random-content)First random string(other)Second random string(other)Third random string(other)...(/random-content)"]
[string]...[string]...[string][/random-content]`
The `[string]` shortcode displays the string of characters.
Example (random image taken from the short film Big Buck Bunny):
`[random-content string="(random-number min=1 max=30 digits=2)"]
[/random-content]`
= Variable Contents =
To display a COOKIE, ENV, GET, POST, SERVER or SESSION variable, insert into your posts/pages/widgets a code like this:
`[variable-string type=type name=name]`
The "type" attribute can be equal to "cookie", "env", "get", "post", "server" or "session". Its default value is "get". The "name" attribute is the name of the variable.
To display a variable content, insert into your posts/pages/widgets a code like this:
`[variable-content]
Default content[other]
First alternate content[other]
Second alternate content[other]
...
[/variable-content]`
The displayed content is not random but is determined by the URL of the page.
Pages displaying the default content:
http://permalink-of-the-page/
http://permalink-of-the-page/?content=0
Page displaying the first alternate content:
http://permalink-of-the-page/?content=1
Page displaying the second alternate content:
http://permalink-of-the-page/?content=2
This is the value of the "content" variable of the URL which determines the displayed content. If its value:
- is equal to 0 or is not specified, then the displayed content is the default content
- is equal to 1, then the displayed content is the first alternate content
- is equal to 2, then the displayed content is the second alternate content
- ...
Example:
`[variable-content]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/variable-content]`
Pages displaying the default content:
http://permalink-of-the-page/
http://permalink-of-the-page/?content=0
Page displaying the first alternate content:
http://permalink-of-the-page/?content=1
Page displaying the second alternate content:
http://permalink-of-the-page/?content=2
Page displaying the third alternate content:
http://permalink-of-the-page/?content=3
If you don't want to use a GET variable to display the variable content, you can also do the same thing with a [COOKIE, ENV, POST, SERVER or SESSION](http://www.php.net/manual/en/reserved.variables.php) variable using the "type" attribute.
You can specify a name different than "content" for the variable using the "name" attribute:
Example:
`[variable-content name=lyric]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/variable-content]`
Pages displaying the default content:
http://permalink-of-the-page/
http://permalink-of-the-page/?lyric=0
Page displaying the first alternate content:
http://permalink-of-the-page/?lyric=1
Page displaying the second alternate content:
http://permalink-of-the-page/?lyric=2
Page displaying the third alternate content:
http://permalink-of-the-page/?lyric=3
You can specify values different than numbers for the variable using the "values" attribute.
Example:
`[variable-content name=lyric values=first/second/third/fourth]
Somewhere over the rainbow, way up high[other]
There's a land that I heard of, once in a lullaby[other]
Somewhere over the rainbow, skies are blue[other]
And the dreams that you dare to dream, really do come true
[/variable-content]`
Pages displaying the first lyric:
http://permalink-of-the-page/
http://permalink-of-the-page/?lyric=first
Page displaying the second lyric:
http://permalink-of-the-page/?lyric=second
Page displaying the third lyric:
http://permalink-of-the-page/?lyric=third
Page displaying the fourth lyric:
http://permalink-of-the-page/?lyric=fourth
You can display the value of the variable. To do this, simply use only the default content without specifying any alternate content. If the value of the variable is not specified in the URL, the default content will be displayed:
`[variable-content name=name]Default content[/variable-content]`
Example:
`Welcome [variable-content name=first-name]to You[/variable-content]!`
Page displaying your first name:
http://permalink-of-the-page/?first-name=your-first-name
= Google Optimizer =
To use Google Optimizer, you must have an account. Sign up for one if you do not. Through the website of Google Optimizer, create a new experiment.
Click on "Multivariate Experiment" and on "Create". You will arrive on this page:
New multivariate experiment - Step 1
Enter a name for your experiment, enter the address of your test page, the address of your conversion page, and click on "Continue".
New multivariate experiment - Step 2
Select "You will install and validate the JavaScript tags", and click on "Continue". You will arrive on a page where you can get your control, tracking, and conversion scripts.
You will find your tracking ID in your tracking script. It's a string of characters which starts with "UA":
`var gwoTracker=_gat._getTracker("UA-XXXXXXXX-X");`
Enter your tracking ID in the "Google Optimizer Account Tracking ID" field in the options page of Content Switcher, check the "Add JavaScript code" box and click on "Save Changes".
For your test page, create the "optimizer" (in lowercase letters) custom field and enter the string starting with "/" and ending with "/test" in your tracking script:
`gwoTracker._trackPageview("/XXXXXXXXXX/test");`
Insert into the content of your test page at least a code like this:
`[optimizer-content name="Name of your content"]
Your original content[/optimizer-content]`
Don't forget to include the quotes at the beginning and the end of the name value:
Example:
`[optimizer-content name="Title"]