Mixing php with html tags

I am trying to implement the below code, but as a result get displayed nothing back.

 <li class="cleanup">Garantie:<span><?php (get_post_meta(get_the_ID(), 'Garantie', true); ?> Jahre</span><?php echo (get_post_meta(get_the_ID(), 'Garantie', true) >= 2) ? ('<span class="pro_con pro"><i class="fa fa-check"></i>Lange Garantie: ' . <?php (get_post_meta(get_the_ID(), 'Garantie', true)); ?> . ' Jahre</span>') : ('<span class="pro_con pro"><i class="fa fa-check"></i>Standart Garantie: ' . <?php (get_post_meta(get_the_ID(), 'Garantie', true)); ?> . ' Jahre</span>'; ?>) </li>

The field should be available and the function get_post_meta does work!

Read More

I assume that I have a syntax error, but I am not sure where?

Any suggestions what I am doing wrong?

I appreciate your replies!

Related posts

4 comments

  1. You have an extra parenthesis, change to

    <?php get_post_meta(get_the_ID(), 'Garantie', true); ?>
    //   ^ it was here
    

    And by the way, you must have your logging on on devel env, logs help a lot.

  2. You have some extra closing ?> php tags inside the Ternary operator.

    Modified Code:

     <li class="cleanup">Garantie:
     <span>
     <?php get_post_meta(get_the_ID(), 'Garantie', true); ?> Jahre
     </span>
     <?php 
     echo (get_post_meta(get_the_ID(), 'Garantie', true) >= 2) ? 
     ('<span class="pro_con pro"> <i class="fa fa-check"></i>Lange Garantie: ' . 
     (get_post_meta(get_the_ID(), 'Garantie', true)) . ' Jahre</span>') : 
     ('<span class="pro_con pro"> <i class="fa fa-check"></i>Standart Garantie: ' . 
        (get_post_meta(get_the_ID(), 'Garantie', true)) . ' Jahre</span>' ) ;
    ?>
     </li>
    
  3. Try this :

        <li class="cleanup">Garantie:<span><?php (get_post_meta(get_the_ID(), 'Garantie', true); ?> Jahre</span>
    <?php echo (get_post_meta(get_the_ID(), 'Garantie', true) >= 2) ? '<span class="pro_con pro"><i class="fa fa-check"></i>Lange Garantie: ' . get_post_meta(get_the_ID(), 'Garantie', true) . ' Jahre</span>' : '<span class="pro_con pro"><i class="fa fa-check"></i>Standart Garantie: ' . get_post_meta(get_the_ID(), 'Garantie', true) . ' Jahre</span>'; ?> </li>
    
  4. How about something like this:

     <li class="cleanup">
        Garantie:
        <span>
            <?php echo get_post_meta(get_the_ID(), 'Garantie', true); ?> Jahre
        </span>
        <?php 
            if(get_post_meta(get_the_ID(), 'Garantie', true) >= 2){
                echo '<span class="pro_con pro"><i class="fa fa-check"></i>Lange Garantie: ';
                echo get_post_meta(get_the_ID(), 'Garantie', true);
            }else{
                echo '<span class="pro_con pro"><i class="fa fa-check"></i>Standart Garantie: ';
                echo get_post_meta(get_the_ID(), 'Garantie', true);
            }
            echo " Jahre</span>";
        ?>
    </li>
    

    Afterall, readability counts…

Comments are closed.