如果缩略图图像否则发布标题

时间:2018-03-03 作者:JJ187

我的网站上有一个结果表,我想在缺少特色图片时显示文章标题,在缺少exlink时不显示按钮。

img class=“logo”-是需要其他标题的特色图像

a class=“exlink”-是需要“否则不显示”按钮的链接(几乎一直向下)

这是从页面模板复制粘贴的:

    <?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(); ?> 

1 个回复
SO网友:Beee

请检查this page.

if ( has_post_thumbnail( $post_id ) {
    // has thumbnail, so show thumbnail
} else {
    echo the_title();
}
类exlink似乎是硬编码的,没有涉及IF,因此我不知道您想将其与什么进行比较。

结束

相关推荐

Functions.php过滤器未应用于AJAX调用

我已经使用php向菜单中添加了一个元素(为了便于说明,简化了代码):add_filter( \'wp_nav_menu_\' . $menu_slug . \'_items\', \'add_menu_item\' , 10, 2 ); function add_menu_item ( $items ) { $item = sprintf(\'<li class=\"custom-item\">%s</li>\', menu_item_content ()