DaThemeDude
DaThemeDude

Reputation: 33

How to if/else a class name inside an existing function?

I currently have a function (shown below is just a snippet). I would like to put an if/else inside this though, so if a certain div class exists, output X code, else output Y.

What would be the correct way? I have tried a few things with no luck.

A snippet of my existing code -

    $fields = array(

    'author' =>
    '<div class="c4">' .
    '<input id="author" name="author" type="text" size="30" placeholder="' . __( 'Your Name (required)', 'pacha' ) . '" />' .
    '</div>',

    'email' =>
    '<div class="c4">' .
    '<input id="email" name="email" type="text" size="30" placeholder="' . __( 'Your Email (required)*', 'pacha' ) . '" />' .
    '</div>',

    'url' =>
    '<div class="c4">'  .
    '<input name="url" size="30" id="url" type="text" placeholder="' . __( 'Your Website (optional)', 'pacha' ) . '" />' .
    '</div>',

);

Where basically if a certain div class exists I would like the above divs to be c12, else stay at c4.

thanks

Upvotes: 1

Views: 43

Answers (1)

Parixit
Parixit

Reputation: 3855

Something like this:

if(YOUR_CONDITION_TRUE) {
     $class_name = "c12";
} else {
     $class_name = "c4";
}

$fields = array(

    'author' =>
    '<div class="'.$class_name.'">' .
    '<input id="author" name="author" type="text" size="30" placeholder="' . __( 'Your Name (required)', 'pacha' ) . '" />' .
    '</div>',

    'email' =>
    '<div class="'.$class_name.'">' .
    '<input id="email" name="email" type="text" size="30" placeholder="' . __( 'Your Email (required)*', 'pacha' ) . '" />' .
    '</div>',

    'url' =>
    '<div class="'.$class_name.'">'  .
    '<input name="url" size="30" id="url" type="text" placeholder="' . __( 'Your Website (optional)', 'pacha' ) . '" />' .
    '</div>',

);

Upvotes: 1

Related Questions