|
Ever get to the point on blogger when you wish you could just...add a "Second nickname" field to each user form? I know I have. This is a tutorial to help you do basically that. I'll show you two ways to create a superuser controlled nickname. basically, that means that whoever makes the template will be able to choose what nickname is displayed. A handy thing sometimes.
The first way is using Javascript. There are actually two ways of doing it in Javascript, I'll only show you one, which uses a small function. I'll give the whole script, and then break it down.
<script language="JavaScript">
function ishallcallthem(me) {
if (me == "Aaron") {
document.write("The Coding One");
} else if (me == "Mike") {
document.write("The Wishing One");
} else {
document.write("The Unknown One");
}
}
</script>
<script language="JavaScript">
function ishallcallthem(<$BlogItemAuthorNickname$>);
<script language="JavaScript">
Line 1: <script language="JavaScript">
Here, we tell the browser that this is JavaScript. Easy enough.
Line 2: function ishallcallthem(me) {
Now We define the function ishallcallthem(). me is the variable we will later place the nickname blogger provides.
Line 3: if (me == "Aaron") {
JavaScript is very easy to read, here I'm saying that if the variable Me is Aaron, then...(you change Aaron to whatever nickname you want to change first)
Line 4: document.write("The Coding One");
display on the document, the coding one. (and you change the Coding One to whatever you want it to display)
Line 5: } else if (me == "Mike") {
This is what starts one of two lines that you will replicate to display more than one person's nickname. It's saying, that if it's not Aaron, and is Mike, then...(you change Mike to whatever next person you want to change the nickname of...)
Line 6: document.write("The Wishing One");
Display on the document, the wishing one. This is the second line you use for more than one person's nickname. (and change the Wishing One to what you want to change it to)
Line 7: } else {
This says, if it's not any of the above...
Line 8: document.write("The Unknown One");
then display The Unknown One (Change The Unknown One to whatever you want it to display if they aren't in the above one. don't take this out, it's very nice and helpful.)
Line 9: }
and it ends the whole if statement.
Line 10: }
and it ends the whole ishallcallthem() function
Line 11: </script>
And, while we're at ending things, this ends the whole top definition javascript stuff.
Line 12: <script language="JavaScript">
function ishallcallthem(<$BlogItemAuthorNickname$>);
<script language="JavaScript">
Place this where you want the nickname to be displayed. What this does, is it calls the function ishallcallthem(), puts the nickname in, is processed by the javascript before it, and spits it back out.
The second way I'll show is the more secure of the two. By more secure, I'm meaning that nobody is going to figure out just who is behind that nickname if you don't want them to. In the first one, a quick peek at the code would divulge the identity. Sometimes you may want that, but othertimes, not. This one, however, is PHP, so you have to have that enabled on your server for it to work. this is what it looks like:
<?
if ("<$BlogItemAuthorNickname$>" == "Aaron") {
echo "the Coding One";
} elseif ("<$BlogItemAuthorNickname$>" == "Mike") {
echo "the Wishing One";
} else {
echo "the Unknown One";
}
?>
Line 1: <?
This states, "Server, this is PHP. process this". You put this whole code where you want to display the nickname.
Line 2: if ("<$BlogItemAuthorNickname$>" == "Aaron") {
again, pretty straightfoward. if the nickname is Aaron..(Change Aaron to the nickname of the person you want to use first)
Line 3: echo "the Coding One";
display on the page the Coding One. (Change the Coding One to whatever you want their nickname to be)
Line 4: } elseif ("<$BlogItemAuthorNickname$>" == "Mike") {
This is what starts one of two lines that you will replicate to display more than one person's nickname. It's saying, that if it's not Aaron, and is Mike, then...(you change Mike to whatever next person you want to change the nickname of...)
Line 5: echo "the Wishing One";
Display on the document, the wishing one. This is the second line you use for more than one person's nickname. (and change the Wishing One to what you want to change it to)
Line 6: } else {
This says, if it's not any of the above...
Line 7: echo "the Unknown One";
then display The Unknown One (Change The Unknown One to whatever you want it to display if they aren't in the above one. don't take this out, it's very nice and helpful.)
Line 8: }
and it ends the whole if statement.
Line 9: ?>
And, while we're at ending things, this ends the whole PHP declaration.
Well, that's it. two ways of displaying that. have lots of fun! You can also modify the script to display other different things, such as an im link for each person, or an image of each person who is posting.
|