• Resolved tudorc11

    (@tudorc11)


    I want to use the following code to display some text at the top of each category page. But, for some reasons, both echo statements are executed. I am new with PHP, it may be something very simple..

    <h3>
         <?php
    	$catTitle=single_cat_title();
    	if($catTitle == "Alinuta") echo $catTitle;
    	else echo "Banc fara Alinuta";
         ?>
    </h3>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    explanation: not both echo statements are executed, as you could easily see if you would echo any other text.
    the first output comes from single_cat_title() directly (the one before the if) and the second comes from the else because your if statement is not true ($catTitle is empty).

    to use the cat title in a conditional statement (i.e. as a string) you have to use:

    http://codex.wordpress.org/Function_Reference/single_cat_title

    <h3>
         <?php
    	$catTitle=single_cat_title('', false);
    	if($catTitle == "Alinuta") echo $catTitle;
    	else echo "Banc fara Alinuta";
         ?>
    </h3>
    Thread Starter tudorc11

    (@tudorc11)

    It works. Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Simple if…else statement not working (executes both blocks of code)’ is closed to new replies.