• Hi all what is the correct syntax for this if else clause, I think I have the syntax slightly wrong. When the category is French I want it to show nothing and when it is other categories I want it to show the string “Learn About”. Thank you

    `<h1 class=”pagetitle”>
    <?php } if (is_category(‘French’)) { ?>
    <?php } else { ?>
    Learn about <?php printf(__(‘%s’, ‘kubrick’), single_cat_title(”, false)); ?></h1>
    `

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try removing the curley braces from this line:
    <?php } if (is_category('French')) { ?>

    Thread Starter Copywrite

    (@copywrite2012)

    Thank you!

    Thread Starter Copywrite

    (@copywrite2012)

    It doesn’t work ??

    <?php /* If this is a category archive */ if (is_category()) { ?>
    <h1 class="pagetitle">
    <?php if ( is_category('French class'))  ?>
    <?php } else { ?>
    Learn <?php printf(__('%s', 'kubrick'), single_cat_title('', false)); ?></h1>
    <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>

    Sorry – I wasn’t clear…you need one of the curley braces so it should look like this:
    <?php if ( is_category('French class')) { ?>

    Thread Starter Copywrite

    (@copywrite2012)

    Thanks for the reply, that doesn’t seem to work:

    <?php /* If this is a category archive */ if (is_category()) { ?>
    <h1 class="pagetitle">
    <?php if ( is_category('French Class')) { ?>
    <?php } else { ?>
    Learn <?php printf(__('%s', 'kubrick'), single_cat_title('', false)); ?></h1>
    <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    Thread Starter Copywrite

    (@copywrite2012)

    maybe I just need to get rid of the first bracket here?
    <?php } else { ?>

    Indented your code to make it readable, and used : instead of {}

    <?php if (is_category()) : ?>
        <?php /* If this is a category archive */ ?>
    	<h1 class="pagetitle">
    		<?php if ( is_category('French')) : ?>
    		      <!-- Do Nothing Here -->
    		<?php else : ?>
    			Learn <?php printf(__('%s', 'kubrick'), single_cat_title('', false)); ?>
    		<?php endif; ?>
    	</h1>
    <?php elseif (is_tag()) : ?>
      <?php /* If this is a tag archive */ ?>
          <!-- Do stuff Here -->
    <?php endif; ?>

    There is no output for category ‘French’ so you could just use ! which is the operator ‘not’

    <?php if (is_category()) : ?>
        <?php /* If this is a category archive */ ?>
    	<h1 class="pagetitle">
    		<?php if ( !is_category('French')) : ?>
    			Learn <?php printf(__('%s', 'kubrick'), single_cat_title('', false)); ?>
    		<?php endif; ?>
    	</h1>
    <?php elseif (is_tag()) : ?>
      <?php /* If this is a tag archive */ ?>
          <!-- Do stuff Here -->
    <?php endif; ?>

    HTH

    David

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘if else code’ is closed to new replies.