uCoz Community uCoz Modules Additional Features Conditional Operators (<?if($VAR$)?>...<?else?>...<?endif?>) |
Conditional Operators |
Conditional operators for newbies and professionals. If you do not understand how conditional operators work and the information in the Control Panel is not enough for you, I will try to explain. First, you should believe, that it is very easy! Conditional operators are special codes-symbols, which can perform certain scenarios (scripts). You can create an absolutely new option on your site that is not provided in the Control Panel. First, you must understand and get used to the components of the script code. They are: <?if($code$)?> – it is some condition (code), which points to the operator whom and what we are dealing with. We can mentally replace it by the phrase «If there is»; <?else?> – it is the operator which will do what you say if the condition corresponds to the indicated ones. Replace it mentally by the phrase «If not»; <?endif?> – it is the end of the conditional operator, replace it mentally by «The end»;
Now let’s examine an easy example from the Control Panel: (from Page Editor) <?if($USER_LOGGED_IN$)?> Hello, $USERNAME$ <?else?> You are a GUEST. Please, register. <?endif?> In our language it means: «If there is an authorized user, then «Hello, his/her login!», if not, «Hello, guest!» and the end.» Now the details. What did we use? We said to <?if($code$)?> operator that our script is intended for saying hello to authorized users. We put the following code instead of $code$ - $USER_LOGGED_IN$ , i.e. we said «If there is an authorized user - <?if($USER_LOGGED_IN$)?>». Then the information, available only to authorized users, follows. At the same time, we may use conditions if they do not correspond to the indicated ones, in our example it is Guests. Therefore, after the information for registered users we enter the information for guests. We get Now we have just to close it. We can also exclude Guests and display information for registered users only. For this purpose we just do not use «If not». We get the following: <?if($USER_LOGGED_IN$)?> We are glad that you have registered! <?endif?> It means that only those who have logged in will see the phrase «We are glad that you have registered!». Any code, specified as working for a certain module, can be a condition for the work of operators. In our case (Page Editor), the following examples can be used: Login and logout: Days after registration: And so on.
Conditions for a script can be changed by means of additional capabilities, supported by the operators. They are «=», «>», «<» signs. If necessary, the equated conditions are separated by a vertical line. After the sign, you say to the operator to whom the whole script is directed. <?if($code$='condition')?> I can see this <?else?> And here I can see this <?endif?> Or <?if($code$='condition')?> The main thing is that I can see this <?endif?> Example: <?if($USER$='John')?> John, don’t forget to read e-mail every day. <?endif?> It means «If there are usernames and there is John among them (='John'), then this is to be displayed to him…» The same is with groups, names, gender, date etc. <?if($USER$='Mike' or $USER$='Lola')?> Mike and Lola, here is a secret link …. <?endif?> Groups: And so on. However, operators can work in each other. Example: <?if($USER_LOGGED_IN$)?> Hello $USER$! <?if($GROUP_ID$=3 || $GROUP_ID$=4)?> Don’t forget to click on the ads! <?endif?> <?else?> Please, register. <?endif?> The script is the following: «If there are logged-in users, then Hello, if there Administrators and Moderators among them, then add Click on ads, if there are unregistered users, we ask them to register, and the end.»
The main thing is that you must think well how to write a script, what codes to use and whom they will be directed to. You may write anything, uCoz is very flexible! Additional mini-info: I'm not active on the forum anymore. Please contact other forum staff.
|
Sunny, Hello ,
I have a question about conditional operators and Informers. ---> [ Photo Albums · Categories · Columns: 3 ] I made a informer to display Photo Album categories on my photo album mainpage. My problem with this is that they display from old to new the first categorie that is created will display first and the second one obviously as the second one.. and so on.. But for my kind of photo album i want to do the opposite I want to display my informer like this: Instead of Old to newest created categorie i want the newest created categorie to display first and the older ones after that. Is this possible with conditional operators ? ----------------------------------------------------------------------------------------------------------------------- Some information you might find useful to understand what i would like to achieve. Informer: Informer section: [ Photo Albums · Categories · Columns: 3 ] (is correct) Informer layout: Code <span class="uphoto" style="text-align: center; vertical-align: top; display: inline-block;"> <span class="photo-block"> <span class="ph-wrap"> <span class="ph-tc" style="max-width:233px!important;max-height:233x!important;"><span style="position:absolute!important;"class="dropcap" class="text-center">$NUMBER$</span><span style="font-size: 1.6em;font-family: 'Open Sans', 'OpenSansExtrabold', 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; color: #fff; font-weight: 800; line-height: 1.4; ;position:absolute;margin:auto;color:#fff;top:42%;bottom:0;left:0;right:0;"><b>$NUM_DATA$ Foto's</b></span><img src="http://foto-davy.do.am/css/UI.jpg"style="max-width:233px!important;max-height:233x!important;" alt="" title="" /></span> <a href="$$CATEGORY_URL$" data-url="$CATEGORY_URL$" class="ph-link" title="$NUMBER$"> <span class="ph-tc"> <span class="ph-data"> <span class="ph-date">$DATE$</span> <span class="ph-descr"><?if(len($PHOTO_DESCR$)>120)?><?substr($PHOTO_DESCR$,0,117)?>...<?else?>$PHOTO_DESCR$<?endif?></span> <span class="ph-author" href="$PROFILE_URL$">$USER$</span> </span> </span> </a> </span> <span class="ph-details ph-js-details"> <span style="margin-top:4px!important">$CATEGORY_NAME$ </span> </span> is also correct. But i have no idea how to display the informers from new to old instead of old to new. (this probably needs to be done with conditional operators) Best regards Animorph. To busy building a passive income online ;)
|
Animorph, categories are displayed in the informer in the same order they are displayed in Control Panel. So if you change the order in the CP (the 'Organize categories' option), the order will change in the informer as well.
I'm not active on the forum anymore. Please contact other forum staff.
|
<title>$SITE_NAME$ - $MODULE_NAME$</title> overwrites any conditional operator. (title) It would have been better if <title>$SITE_NAME$ - $MODULE_NAME$</title> applied to all pages except for the ones that use conditional operators. So that the conditional operator would overwrite <title>$SITE_NAME$ - $MODULE_NAME$</title> and not the other way around. It is not necessary to remove the default code for title. In your example, if it is page200 - its specific title/meta tags will be displayed, if it is any other page - the default title will be displayed. In other words, the default title will be displayed on all pages where their specific titles are not set. The default title will not overwrite your conditions. It is the other way around. If i don't remove Code <title>$SITE_NAME$ - $MODULE_NAME$</title> Code <title>$SITE_NAME$ - $MODULE_NAME$</title> _________________________________ I also use this : <?if($URI_ID$='page5')?> <title>About page 5</title> <meta name="description" content="Page 5 is the best. Welcome to page 5."> <meta name="keywords" content="page 5, page, about page 5"> <link rel="alternate" href="http://about.ucoz.com/index/0-5" hreflang="en" /> <link rel="alternate" href="http://about.ucoz.com/index/0-6" hreflang="de" /> <?endif?> BUT it doesn't take into account the red part ! (it doesn't insert it in the page 5). Need Help. Thank you. Thassos Island Portal :
https://thassos.one Post edited by Urs - Sunday, 2015-05-17, 3:11 PM
|
Hello,
I managed to make the red text work on this domain : http://thassos.ucoz.com/ (it seems i forgot to put in on the first page, and then i only checked there to see if it was really working). Do you think there is a problem that so much white space appears in the source code of the site ? (CTRL + U in firefox) Also this code : Code <title>$SITE_NAME$ - $MODULE_NAME$</title> Written before the conditional operator seems to overwrite them in the browser. ( the titles ) If it is written after them, it doesn't seem to do that. But in both cases you end up if you look at the source code of the site (CTRL + U in firefox) with two titles, which is a big problem because search engines will consider it a mistake. Best Regards. Thassos Island Portal :
https://thassos.one Post edited by Urs - Monday, 2015-05-18, 8:36 PM
|
Written before the conditional operator seems to overwrite them in the browser. ( the titles ) If it is written after them, it doesn't seem to do that. I suggest that you try to include it into the conditional operators. Haven't tested it but it should resolve the problem with two titles. Smth like this: Code <?if($URI_ID$='page5')?> <title>About page 5</title> <?if($URI_ID$='page6')?> <title>About page 6</title> <?else?> <title>$SITE_NAME$ - $MODULE_NAME$</title> <?endif?> <?endif?> Quote Do you think there is a problem that so much white space appears in the source code of the site ? (CTRL + U in firefox) I don't think it's a problem but I'm not 100% sure. Is the page HTML code in the CP okay, without the space? I'm not active on the forum anymore. Please contact other forum staff.
|
It doesn't work.
Your code looks good, but in reality the system interprets it in such a way that only the first command is taken into consideration, while the rest of the pages display nothing. Try it. (maybe i am wrong) The HTMLin control panel "site pages" looks good, but because you have tons of conditional operators when you actually visit the a page in the site and check the source code you see pages of white space, where nothing is written. Just praying the SEO module comes sooner to English language since i don't want to mess with the Russian one then change back to English for normal use, because it may even overwrite some of the stuff ?! Thassos Island Portal :
https://thassos.one |
How can i get diferent color of reputation numbers,for example if there is minus reputation it will be red numbers shown and plus green color. i try
Code <?if($REP_RATING$>20)?> <div class="rep_plus">$_REPUTATION$</div> Code <?if($_REPUTATION$='20')?> !
Post edited by Ed05 - Thursday, 2015-05-28, 8:13 PM
|
Hello guys!
I want to sort my entries with categories or tags! I create code with logical operators! For example i have three categories: "soccer", "photos" and "videos"! i create page named "latest videos"! i want create code which sort categories names and in my "latest videos" appear only videos! this is my code which don't work LOL ! Code <?if($CATEGORIES$ = 'videos')?>$SOMETHING$<?endif?> ©Levani Jincharadze |
hello guys i know this problem is here how to hide the user counter to all user and other visitor only me can see the user counter please help me thankss
Attachments:
2123861.png
(10.1 Kb)
|
helte6213, maybe with the things from the title of the thread?
hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau sometimes i lurk here |
What code would i use for text "be first to comment this"
Added (2015-10-05, 11:50 PM) !
Post edited by Ed05 - Monday, 2015-10-05, 11:44 PM
|
| |||