将元素应用于过滤的ACF值

时间:2014-09-18 18:30:26

标签: php wordpress filter advanced-custom-fields

我试图在我的档案中的某些术语图像上放置一个元素(角色功能区)。我使用高级自定义字段为某些字词分配值。然而,下面的代码在每个术语上都放了一个功能区,而不只是带有" active15"价值相关。有人可以帮我解决我做错的事吗?

这个LINK显示了正在发生的事情的样本。铝是唯一应该有色带的图像,但由于某种原因,似乎过滤器似乎没有应用。

      <!-- 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 -->

获取/显示页面条款的代码

<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 个答案:

答案 0 :(得分:0)

我设法使用以下方法找到修复程序。通过将我的代码移动到else语句,使其显示正确的术语。对此有点奇怪,但它运作正常!

 <?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 } ?>