1

So what i would like to do is order in some CSS depending on the value of a custom field.

The code below just says that if there is ANY value, do X, else do nothing...

<?php $pageNumbered=get_post_meta($post->ID, 'page-number', true); ?>
    <?php if ( $pageNumbered ) : ?>
        <div class="page-number left">
            <?php echo get_post_meta($post->ID, "page-number", true); ?>
        </div>              
        <?php else : ?>

    <?php endif; ?>

...what i want to do is say if the value is X do Y, if it is Z do XY etc etc...

Thanks guys!

3
  • So why not add in a couple of simple if conditions?
    – t31os
    Apr 12, 2011 at 13:29
  • Yeah, but what i am saying is that i don't know how to bind a specific value to the if condition
    – Infocentre
    Apr 12, 2011 at 13:32
  • 3
    This is a PHP question, not a WordPress question. I vote we move it over to stack overflow. Apr 12, 2011 at 13:34

1 Answer 1

1

Sorry but it's not clear what you want to do. From what I understand is you simply want to use an elseif statement:

<?php $pageNumbered=get_post_meta($post->ID, 'page-number', true); ?>

<?php if ( $pageNumbered ) : ?>
    <div class="page-number left">
        <?php echo get_post_meta($post->ID, "page-number", true); ?>
    </div>              
<?php elseif($pageNumbered == "Z") : ?>
    <div class="page-number left">
        <?php echo get_post_meta($post->ID, "page-number", true); ?>
    </div>
<?php endif; ?>

If you can edit you question to be clearer then I might be able to help more.

3
  • Sorry, i was unclear but i think you have just answered my question anyway! == "Z" means that the value must equal Z. Whereas true just needs to contain any value
    – Infocentre
    Apr 12, 2011 at 13:40
  • @Infocentre you know there is an extensive list of syntax's and functions in the php manual :)
    – Xavier
    Apr 12, 2011 at 14:01
  • @infocentre - tizag.com/phpT/elseif.php quick tutorial on elseif PHP statements.
    – Scott
    Apr 12, 2011 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.