PHP - If (condition) in wordpress

1

Next, I have 4 posts in a post type services.

Brides, Day Spa, Aesthetic Medicine and Salon

<div class="service-content <?php if( $post_title == 'Noivas' ) echo "qwp-content"; ?>">
<?php var_dump($post_title); ?>
 <?php the_content(); ?>
</div><!-- /.qwp-content -->

CSS:
.qwp-content { 
    font-size: 1.444rem;
    text-align: center; 

    p:nth-child(odd) {
      color: #000;  
      padding: 7px;
      background: #C5C2B3; 
    }
  }

  .service-content { 
    font-size: 1.444rem;
  }

It was doing so, but not so much of logic and tals.

Basically, what I want is that when the person accesses Brides, it does not take the .qwp-content class and just get .service-content

    
asked by anonymous 28.04.2017 / 15:09

2 answers

2

In this case, you only need to change the operator.

<?php
    $post_title = "Noivas";         
?>

<div class="service-content <?php if( $post_title != 'Noivas' ) echo "qwp-content";  ?>">
    <p> teste </p>
</div>

I particularly suggest you make the condition out of class, so you can reuse elsewhere. Ex:

<?php
        $post_title = "Não sou noiva";
        $qwp = '';
        if( $post_title != 'Noivas' ) {
            $qwp = "qwp-content";
        }
?>

<div class="service-content <?php echo $qwp ;  ?>">
    <p> teste </p>
</div>

<div class="service-main <?php echo $qwp ;  ?>">
    <p> teste </p>
</div>
    
28.04.2017 / 16:00
0

Try to do so.

<div class="service-content <?php echo get_the_title() != 'Noivas' ? 'qwp-content' : '' ?>">
    
28.04.2017 / 15:54