Conditional Operators
Sunny
Posts: 9296
Reputation: 456

Message # 1 | 9:47 AM
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
<?if($USER_LOGGED_IN$)?> Hello, $USERNAME$ <?else?> Hello, Guest!

Now we have just to close it.
<?if($USER_LOGGED_IN$)?> Hello, $USERNAME$ <?else?> Hello, Guest! <?endif?>

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:
<?if($USER_LOGGED_IN$)?> <a href="$LOGOUT_LINK$">LOG OUT</a> <?else?> <a href="$LOGIN_LINK$">LOG IN</a> <?endif?>

Days after registration:
<?if($USER_LOGGED_IN$)?> You are with us for $USER_REG_DAYS$ days! <?else?> Please, register. <?endif?>

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.
More examples:

<?if($USER$='Mike' or $USER$='Lola')?> Mike and Lola, here is a secret link …. <?endif?>

Groups:
<?if($GROUP_ID$=3 or $GROUP_ID$=4)?> Moderators and Administrators, click on the ad here… <?endif?>

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:


  • The number of <?if($code$)?> and <?endif?> must be the same.
  • <?else?> is necessary if we output information for those, who don’t meet the conditions, otherwise it is not needed.
  • Alternative conditions or and and (|| and &&) are supported.
  • Nesting of operators is supported.
  • Comparing of variables to each other is supported: <?if($VAR1$=$VAR2$)?>
  • The text must be in quotes when comparing: <?if($USER$='Mike') ?>

    I'm not active on the forum anymore. Please contact other forum staff.
  • Sunny
    Posts: 9296
    Reputation: 456

    Message # 61 | 8:56 AM
    Zain, use $GROUP_ID$ instead of $CUR_GROUP_ID$.
    I'm not active on the forum anymore. Please contact other forum staff.
    Zain
    Posts: 68
    Reputation: -7

    Message # 62 | 10:38 AM
    ok thanks

    Added (2010-10-28, 4:38 Am)
    ---------------------------------------------
    i use the $GROUP_ID$ but it's not work too check the codes.

    Code

    <?if($GROUP_ID$=1)?><img src="http://dl4uall.com/images/user.png" alt="User" border="0"><?endif?>
    <?if($GROUP_ID$=2)?><img src="http://dl4uall.com/images/author.png" alt="Author" border="0"><?endif?>
    <?if($GROUP_ID$=3)?><img src="http://dl4uall.com/images/mod.png" alt="Moderator" border="0"><?endif?>
    <?if($GROUP_ID$=4)?><img src="http://dl4uall.com/images/admin.png" alt="Administrator" border="0"><?endif?>
    <?if($GROUP_ID$=251)?><img src="http://dl4uall.com/images/regular.png" alt="Regular" border="0"><?endif?>
    <?if($GROUP_ID$=255)?><img src="http://dl4uall/images/guest.png" alt="Guest" border="0"><?endif?>
    Post edited by Zain - Thursday, 2010-10-28, 10:40 AM
    Sunny
    Posts: 9296
    Reputation: 456

    Message # 63 | 8:43 AM
    Zain, sorry, I am afraid the code $GROUP_ID$ is not available for the Comments template.
    I'm not active on the forum anymore. Please contact other forum staff.
    Zain
    Posts: 68
    Reputation: -7

    Message # 64 | 9:55 AM
    ok no problem
    khen
    Posts: 475
    Reputation: 13

    Message # 65 | 0:53 AM
    I need help regarding this: how to make conditional operators for making each page title and meta tags unique...

    How can I able to make each page title unique in every selection of Next Page.

    This is the Page Title code I used in the Ad Board:

    <title>$SITE_NAME$, Cebu house and lot, apartment, Cebu cars, Cebu real estate, Cebu jobs</title>

    This is the Page Selector highlighted in color yellow:

    When you click number 2 of the Page Selector, the Page Title and Meta Tags I created remain the same. How can I make it unique in every page number?
    Here is the url of my Ad Board: http://www.affordablecebu.com/board/

    I find it difficult to understand ucoz conditional operators.


    Post edited by khen - Tuesday, 2010-12-28, 0:54 AM
    khen
    Posts: 475
    Reputation: 13

    Message # 66 | 1:48 AM
    How can I remove the span class of $CURRENT_PAGE$? The span class of the $CURRENT_PAGE$ in my website (http://www.affordablecebu.com) is currentPage79. I couldn't find this currentPage79 in my CSS.

    I'm using $CURRENT_PAGE$ in order to create unique Page Titles and Meta Tags by adding $CURRENT_PAGE$ to them. But the problem is the span class currentPage79. The span class currentPage79 also appears in my Page Title. See the snapshot below on how it appears in my browser:


    The span class currentPage79 annoyingly appears in my Page Title.

    How can I remove the span class currentPage79?

    Attachments: 2963494.jpg (30.4 Kb)

    Natashko
    Posts: 3366
    Reputation: 171

    Message # 67 | 9:32 PM
    khen, This is about both of your posts.
    In order to display different titles in different pages of the entries list you should use conditional operators and the system code $CURRENT_PAGE$. This code displays current page number. If page number is 1 (e.g.) the first title should be used e.t.c
    The example of the condition can be: $SITE_NAME$, Cebu house and lot, apartment, Cebu cars, Cebu real estate, Cebu jobs
    The $CURRENT_PAGE$ code doesn’t display just the number (number of the current page). It displays the number in tags.
    khen
    Posts: 475
    Reputation: 13

    Message # 68 | 1:34 AM
    Natashko, yes I want to use the $CURRENT_PAGE$ code but as what I've said above, there is this currentPage79 span class that distracts the $CURRENT_PAGE$ code. Please see Message # 68 (above).

    How can I remove this currentPage79 span class?


    Air
    Posts: 103
    Reputation: 6

    Message # 69 | 2:09 AM
    khen, why not try using the $MODULE_NAME$ operator? It displays the page title (whatever you named the page when it was created).
    Natashko
    Posts: 3366
    Reputation: 171

    Message # 70 | 1:18 PM
    khen,
    Quote (khen)
    How can I remove this currentPage79 span class

    I don't think it is possible.
    SirDarknight
    Posts: 247
    Reputation: -5

    Message # 71 | 11:51 AM
    I want to make a option, that if any user tries to download games he needs to make 5 Posts?

    Design no. 878

    I made this :

    Quote
    <?if($POSTS$>5)?>Download Game<?endif?>

    Where should I put this?

    Animorph
    Posts: 2856
    Reputation: 189

    Message # 72 | 3:51 PM
    go to CP ---> Design ---> Design management(templates) ---> Online Games ----> page with entry full text and his comments

    Find:
    Code
    <?if($LINK_PC$)?><td align="center" valign="top"><a href="$LINK_PC$"><img alt="" border="0" src="/.s/img/icon/download1.png" width="32" height="32"></a><div style="font-size:10px"><a style="text-decoration:none;" href="$LINK_PC$"><!--<s5393>-->Download for<!--</s>--> PC</a></div></td><?endif?>

    replace by:

    Code
    <?if($POSTS$>5)?><?if($LINK_PC$)?><td align="center" valign="top"><a href="$LINK_PC$"><img alt="" border="0" src="/.s/img/icon/download1.png" width="32" height="32"></a><div style="font-size:10px"><a style="text-decoration:none;" href="$LINK_PC$"><!--<s5393>-->Download for<!--</s>--> PC</a></div></td><?endif?><?else?> you need topost 5 posts first<?endif?>

    and this should work then , its better to use the code , like i did in the correct code , then the user will know thy need to post 5 posts first


    To busy building a passive income online ;)
    Natashko
    Posts: 3366
    Reputation: 171

    Message # 73 | 4:06 PM
    SirDarknight, I have answered you here http://forum.ucoz.com/forum/6-12249-1#67836
    SirDarknight
    Posts: 247
    Reputation: -5

    Message # 74 | 4:10 AM
    Animorph, It says
    Quote
    $CALENDAR$ code is used more than once.
    Animorph
    Posts: 2856
    Reputation: 189

    Message # 75 | 11:39 AM
    SirDarknight, it obviously is because you used $CALENDAR$ code on 2 different places , remove one $CALENDAR$ code and then try again
    To busy building a passive income online ;)
    Search: