0

I have a table with results on my website and I want to display post title when featured image is missing and to don't show button when exlink is missing.

img class="logo" - is the featured image that needs to else title

a class="exlink" - is the link that needs to else dont display button (almost all the way down)

This is copypasted from page template:

    <?php 
            query_posts(array( 
                'post_type' => 'mms',
                'showposts' => -1,
                'meta_key' => 'kr',
                'orderby'=>'meta_value_num',
                'order'=>'ASC'
            ) );  
            ?>

            <?php while (have_posts()) : the_post(); 
             // $image1 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),  array(100, 100) );
            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
            ?>
            <div class="mainrecord">


            <div class="col-lg-4 col-sm-4 col-md-4 col-xs-12 logoimage" >
            <img class="logo" src="<?php echo $image[0]; ?>"/>
            <h5 class="wifi"><img src="<?php echo get_template_directory_uri().'/images/wifi-signal-tower(1).png';?>" alt="img"/> <?php the_field('network'); ?></h5>
            </div>
            <div class="col-lg-4 col-sm-4 col-md-4 col-xs-12 services new">
            <h4 class="ctitle">
            <?php 
     //  $values = get_field('select_service');

     $values = get_field('select_service');
    $field = get_field_object('select_service');
    $choices = $field['choices'];
    ?>
    <ul>
    <?php 
    foreach ($choices as $value => $label) {
        ?>



   <?php 
    if (in_array($value, $values)) {
       ?>
       <?php if($value == "Data Rollover") { ?>
       <li><img src="<?php echo get_template_directory_uri().'/images/loading(1).png';?>" alt="img"/><?php echo $value; ?></li>
        <?php } ?> 
        <?php if($value == "Bruk i Eu") { ?>
       <li><img src="<?php echo get_template_directory_uri().'/images/12.png';?>" alt="img"/><?php echo $value; ?></li>
        <?php } ?> 
        <?php if($value == "Fri tale") { ?>
       <li><img src="<?php echo get_template_directory_uri().'/images/phone-call(1).png';?>" alt="img"/><?php echo $value; ?></li>
        <?php } ?> 
        <?php if($value == "Fri SMS/MMS") { ?>
       <li><img src="<?php echo get_template_directory_uri().'/images/e-mail-envelope(1).png';?>" alt="img"/><?php echo $value; ?></li>
        <?php } ?> 
        <?php if($value == "Fri-Fart") { ?>
       <li><img src="<?php echo get_template_directory_uri().'/images/wifi-connection-signal-symbol(1).png';?>" alt="img"/><?php echo $value; ?></li>
        <?php } ?> 

    <?php }
    else { ?>
     <?php if($value == "Data Rollover") { ?>
     <li style="color:#e0e0e0"> <img src="<?php echo get_template_directory_uri().'/images/loading(1).png';?>" alt="img"/><?php echo $value; ?></li>
     <?php } ?>
     <?php if($value == "Bruk i Eu") { ?>
     <li style="color:#e0e0e0"> <img src="<?php echo get_template_directory_uri().'/images/12.png';?>" alt="img"/><?php echo $value; ?></li>
     <?php } ?>
     <?php if($value == "Fri tale") { ?>
     <li style="color:#e0e0e0"> <img src="<?php echo get_template_directory_uri().'/images/phone-call(1).png';?>" alt="img"/><?php echo $value; ?></li>
     <?php } ?> 
     <?php if($value == "Fri SMS/MMS") { ?>
     <li style="color:#e0e0e0"> <img src="<?php echo get_template_directory_uri().'/images/e-mail-envelope(1).png';?>" alt="img"/><?php echo $value; ?></li>
     <?php } ?>
     <?php if($value == "Fri-Fart") { ?>
     <li style="color:#e0e0e0"> <img src="<?php echo get_template_directory_uri().'/images/wifi-connection-signal-symbol(1).png';?>" alt="img"/><?php echo $value; ?></li>
     <?php } ?> 
<?php   }
    ?>

<?php } ?>
</ul>


            </h4>
            <p class="thgb"><?php the_field('set_mb'); ?><br>GB</p>
            </div>
            <!--<div class="col-lg-2 col-sm-2 col-md-2 col-xs-12 mb">
            <p><?php// the_field('set_mb'); ?> <br/>GB</p>
            </div>-->
        <!--    <div class="col-lg-2 col-sm-2 col-md-2 col-xs-12 selectany">
            <p><?php //the_field('select_any'); ?></p>
            </div>-->
            <div class="col-lg-4 col-sm-4 col-md-4 col-xs-12 prices">
                <div class="priceinner">
                <?php $old = get_field( "mandespris" );
                    if( $old ) {
                ?>
                <p class="pricw"><span class="newprice">kr <?php the_field('kr'); ?>,</span>-<br/><span class="oldprice"><del>kr <?php the_field('mandespris'); ?></del>,</span>-<br/>Pris/måned</p>
                    <?php } else { ?>
                    <p class="pricw">kr <?php the_field('kr'); ?>,-<br/>Pris/måned</p>
                    <?php } ?>

                    <p class="nomonth">
                <a class="exlink" href="<?php the_field('link'); ?>" target="_blank">Les mer </a>
                <?php $value = get_field( "no_of_month" );
                    if( $value ) {
                ?>
                <span class="">* <?php the_field('no_of_month'); ?> Måneder</span>
                    <?php } ?>
                    </p>
                </div>
            </div>
            <div class="accordion_head"><span class="plusminus">+</span>Mer Informasjon</div>
            <div class="accordion_body">
            <!--<p>First Accordian Body, it will have description</p>-->
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
            <div class="rowcontent">
                <p><?php the_field('row1'); ?></p>
            </div>
            </div>
            </div>
            </div>
            <?php endwhile; wp_reset_query(); ?> 
  • regardless of the question, do not ever use query_post – Mark Kaplun Mar 3 '18 at 7:20
  • regarding the qquestion itself, there is a lot of pointless code in there that should have no relevance to the title of the question. I suggest you edit the question and trim the code down to the core of the problem to make it more readable. – Mark Kaplun Mar 3 '18 at 7:24
0

Please check this page.

if ( has_post_thumbnail( $post_id ) {
    // has thumbnail, so show thumbnail
} else {
    echo the_title();
}

The class exlink appears to be hardcoded and there's no IF involved so I don't know what you want to compare it to.

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.