The S2 HowTo Journal

Tips, Tricks, and Tutorials for Basic S2 Customization

Previous Entry Share Next Entry
[paidaccount] Randomized User Pictures
howto_user wrote in s2howto
Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

This tutorial will create the print_random_userpic() function which will print randomized user pictures of your choice anywhere in your style. This code can be called for in any function or class in your style. It may have to be modified in certain cases, however. This override will be placed in the layout layer of your style. If you already have a layout layer, go ahead and edit it. Otherwise, create one with the following steps:

At the Advanced Customization page, select "Your layers". Go to below Create layout-specific layer and select "Layout" for Type. Then click "Create".

That should result in the addition of a new choice on this page. It will have some ID number and say "layout" for type, and "(none)" for name. Next to that, click Edit.

Now you should be presented with the following:

layerinfo "type" = "layout";
layerinfo "name" = "";

At this point, it will be easiest to copy an existing style into your new layout layer. At the Public Layers page, select an existing style from the list of public styles. Click "Raw Source Code" when viewing a style to download the S2 source for that style. Copy the source from this file into the layer edit window for your new layout layer.

Now, you will need to add the following code to the theme layer. First, copy and paste the following code into the layer, making sure to include everything:

function print_random_userpic() {

	var string[] pic;


	var int randpic;
	$randpic = rand(0, ((size $pic) - 1));

	"<img src='$pic[$randpic]' alt='' />";

In the above code, you need to replace (for each) with the user pictures that you'd like to be randomized. Please notice that, though six user pictures are used here, there is no maximum or minimum to the number of user pictures that you can use. Also, you can change the HTML used to determine how the image will be displayed as long as the image's src attribute remains the same. Now, copy and paste the contents of whichever function you want the randomized user pictures to display in of whichever style you will be using into the layer. Then, copy and paste the following code into the layer in the spot where you want the randomized user pictures to display:


You will need to apply your layout layer via the Customize interface in order for your changes to take effect.

Originally based on coding from dianna_wills, formatted and written by aajwind.

Comments Disabled:

Comments have been disabled for this post.


Log in

No account? Create an account