dsg56465 2014-09-18 18:30
浏览 10
已采纳

将元素应用于过滤的ACF值

I'm trying to place an element (corner ribbon) on certain term images in my archive. I'm using Advanced Custom Fields to assign a value to certain terms. The code below however places a ribbon on EVERY term and not just the one's with the "active15" value associated. Can someone help me with what I'm doing wrong?

This LINK shows a sample of what is happening. Aluminum is the only image that should have the ribbon, but for some reason it seems like the filter isn't being applied.

      <!-- Green Ribbon for Top 15 Groups Start -->

              <?php    

      if($terms) {

        foreach($terms as $lc) {

        if( get_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id) != 'active15' ) continue; 
         {
        ?>
<div class="ribbon ribbon-green">
        <div class="banner">
            <div class="text">TOP 15</div>
        </div>
    </div>
                            <?php }      ?>



        <?php 

        }

    }



else 
{
    echo '<div class="ribbon ribbon-blue">
        <div class="banner">
            <div class="text">TOP 15</div>
        </div>
    </div>';

     }
?>
 <!-- Green Ribbon for Top 15 Groups End -->

CODE TO GET/DISPLAY TERMS FOR PAGE

<div class="row">

                        <?php
                        if ( get_query_var( 'paged' ) ) {
                            $paged = get_query_var('paged');
                        }elseif( get_query_var( 'page' ) ) {
                            $paged = get_query_var( 'page' );
                        }else{
                            $paged = 1;
                        }
                        $per_page = 12;
                        #fix
                        $term_args = array(
                            'hide_empty'        => 0,
                             'exclude'           => array(16, 20, 22, 25, 27, 28, 30, 4, 33, 264 ), //* Enter ID's of parent categories to exclude from list 

                        );
                        $number_of_terms = wp_count_terms( 'focus15groups' , $term_args); // This counts the total number terms in the taxonomy with a function)
                        $paged_offset = ($paged - 1) * $per_page;
                        $libargs = array(
                            'orderby'           => 'name',
                            'order'             => 'ASC',
                            'exclude'          => array(16, 20, 22, 25, 27, 28, 30, 4, 33, 264 ), //* Enter ID's of parent categories to exclude from list 
                            'number'            => $per_page,
                            'offset'            => $paged_offset,
                        );  
                        $_libargs = wp_parse_args($term_args, $libargs);
                        $libcats = get_terms( 'focus15groups', $_libargs);  

                        #fix
                        $i = 0;
                        foreach($libcats as $lc){
                            if( $i % 4 == 0 ) { ?>
                                <div class="clearfix"></div>
                            <?php }
                            $i++; ?>
                            <div class="col-lg-3">
                                <?php $termlink = get_term_link( $lc->slug, 'focus15groups' ); ?>
                                <div class="panel panel-default <?php the_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id); ?>">
                <div class="panel-image">

                <!-- Green Ribbon for Top 15 Groups Start -->

              <?php    

      if($terms) {

        foreach($terms as $lc) {

        if( get_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id) != 'active15' ) continue; 
         {
        ?>
<div class="ribbon ribbon-green">
        <div class="banner">
            <div class="text">TOP 15</div>
        </div>
    </div>
                            <?php }      ?>



        <?php 

        }

    }



else 
{
    echo '<div class="ribbon ribbon-blue">
        <div class="banner">
            <div class="text">TOP 15</div>
        </div>
    </div>';

     }
?>
 <!-- Green Ribbon for Top 15 Groups End -->                    

 <?php if( get_field('group_active_in_focus_15', 'focus15groups_'.$term->term_id) != 'active15' )  { ?>
 <div class="ribbon ribbon-green">
        <div class="banner">
            <div class="text">TOP 15</div>
        </div>
    </div>
<?php } else { ?>

<?php } ?>


               <div class="thumbnail">
   <div class="caption">
                <br/><br/>   
                <h1><span class="label label-info"><?php echo  $lc->count  ?></span></h1>
                <p> Symbols </p>
                <h4> <a class="label label-default" href="<?php echo $termlink; ?>"> View Group</a> </h4> 

            </div>

                    <!-- Get Image by Attachment ID Start-->
            <?php 
                $attachment_id = get_field('taximage', 'focus15groups_'.$lc->term_id);
                if ($attachment_id) {
                    $image = wp_get_attachment_image_src($attachment_id, 'industrygroup-img');
                    if ($image) {
                        ?>
                        <img class="img-responsive" src="<?php echo $image[0]; ?>" />
                        <?php 
                    } 
                } 
            else { ?>
<img class="img-responsive" src="http://www.runningalpha.com/wp-content/uploads/2014/08/RA-logo-300px-groups.jpg" alt="<?php the_title(); ?>" />
<?php } ?>
</div>

            <!-- Get Image by Attachment ID End-->

                </div>
                                               <div class="panel-footer text-center"><a href="<?php echo $termlink; ?>"><?php echo $lc->name; ?></a>
                </div>
            </div>      
                            </div>

                      <?php }     ?>
                      </div>
  • 写回答

1条回答 默认 最新

  • du21064 2014-10-06 21:56
    关注

    I managed to find a fix using the following. By moving my code to the else statement made it show for the correct terms. Something seems odd about that, but it works right!

     <?php if( get_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id) != 'active15' )  { ?>
    
    <?php } else { ?>
     <div class="ribbon ribbon-green">
            <div class="banner">
                <div class="text">TOP 15</div>
            </div>
        </div>
    <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)