ACF转发器将字段内容放入选项卡中

时间:2017-10-20 07:32:46

标签: wordpress advanced-custom-fields

我试图在WP Admin仪表板中提供一个简洁易用的客户端后端字段提交,可以将转发器字段数据排序到适当的选项卡式内容中。这是设置。

字段设置 enter image description here

后端 enter image description here

前端 enter image description here

我试过的代码;

<div class="tab-pane fade" id="tab-1-3">

                                <ul class="nav nav-pills" role="tablist">
                                  <li role="presentation" class="active"><a href="#english" aria-controls="english" role="tab" data-toggle="tab">English</a></li>
                                  <li role="presentation"><a href="#spanish" aria-controls="spanish" role="tab" data-toggle="tab">Spanish</a></li>
                                </ul>

                                <div class="tab-content lang-tab-content">
                                    <div role="tabpanel" class="tab-pane active" id="english">
                                        <?php
                                        $count=0; 
                                        if( have_rows('article') ):
                                            while ( have_rows('article') ) : the_row();
                                        ?> 
                                            <?php if (the_sub_field('language') == 'English') { ?>
                                            <strong>Published Date:</strong> <?php the_sub_field('publised_date');?>
                                            <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                                              <div class="panel panel-default">
                                                <div class="panel-heading" role="tab" id="heading<?php echo $count ?>">
                                                  <h4 class="panel-title">
                                                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $count ?>" aria-expanded="false" aria-controls="collapse<?php echo $count ?>">
                                                      <?php the_sub_field('article_title');?>
                                                    </a>
                                                  </h4>
                                                </div>
                                                <div id="collapse<?php echo $count ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading<?php echo $count ?>">
                                                  <div class="panel-body">
                                                    <?php the_sub_field('article_body');?>
                                                  </div>
                                                </div>
                                              </div>
                                            </div>
                                            <?php } ?>
                                        <?php
                                        $count++;
                                            endwhile;
                                        else :
                                        endif;
                                        ?>
                                    </div>
                                    <div role="tabpanel" class="tab-pane" id="spanish">Spanish</div>
                                </div>

                            </div><!-- tab-pane -->

2 个答案:

答案 0 :(得分:0)

请显示循环代码。如果没有关于代码的任何信息,这很难回答。

我只是遍历所有转发器行并设置一个类来隐藏基于首选语言的元素。然后在按钮单击时使用javascript切换类。

更新

 <?php
  $count=0; $english =''; $spanish ='';
  if( have_rows('article') ):
  while ( have_rows('article') ) : the_row();
  $count++;

    if (the_sub_field('language') == 'English'){
    $english .= '<strong>Published Date: '.get_sub_field('publised_date').'</strong>';
    $english .= '<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"><div class="panel panel-default">';
    /** PANEL HEADING **/
    $english .= '<div class="panel-heading" role="tab" id="heading'.$count.'">';
    $english .= '<h4 class="panel-title">';
    $english .= '<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse'.$count.'" aria-expanded="false" aria-controls="collapse'.$count.'">';
    $english .= get_sub_field('article_title');
    $english .= '</a></h4></div>';
    /** END PANEL HEADING **/

    /** COLLAPSE START **/
    $english .= '<div id="collapse'.$count.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading'.$count.'"><div class="panel-body">'.get_sub_field('article_body').'</div></div>';
    /** COLLAPS END **/

    $english .= '</div></div>';

    }
    else{

    $spanish .= '<strong>Published Date: '.get_sub_field('publised_date').'</strong>';
    $spanish .= '<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"><div class="panel panel-default">';
    /** PANEL HEADING **/
    $spanish .= '<div class="panel-heading" role="tab" id="heading'.$count.'">';
    $spanish .= '<h4 class="panel-title">';
    $spanish .= '<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse'.$count.'" aria-expanded="false" aria-controls="collapse'.$count.'">';
    $spanish .= get_sub_field('article_title');
    $spanish .= '</a></h4></div>';
    /** END PANEL HEADING **/

    /** COLLAPSE START **/
    $spanish .= '<div id="collapse'.$count.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading'.$count.'"><div class="panel-body">'.get_sub_field('article_body').'</div></div>';
    /** COLLAPS END **/

    $spanish .= '</div></div>';



    }
  endwhile;
  endif;
                                    ?> 
<div class="tab-content lang-tab-content">
    <div role="tabpanel" class="tab-pane active" id="english">
    <?php echo $english; ?>
    </div>
    <div role="tabpanel" class="tab-pane" id="spanish">
    <?php echo $spanish; ?>
    </div>
</div>

答案 1 :(得分:0)

解决。

                                    <ul class="nav nav-pills" role="tablist">
                                    <li role="presentation" class="active"><a href="#english" aria-controls="english" role="tab" data-toggle="tab">English</a></li>
                                    <li role="presentation"><a href="#spanish" aria-controls="spanish" role="tab" data-toggle="tab">spanish</a></li>
                                </ul>
                                </div>

                                <div class="tab-content lang-tab-content">

                                    <div role="tabpanel" class="tab-pane active" id="english">
                                        <?php $ons=0; if(get_field('own_news')): ?>
                                            <?php while(has_sub_field('own_news')): ?>
                                                <?php if( get_sub_field('language') == 'English' ): ?>
                                                    <strong>Published Date:</strong> <?php the_sub_field('publised_date');?>
                                                    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                                                        <div class="panel panel-default">
                                                            <div class="panel-heading" role="tab" id="heading<?php echo $ons ?>">
                                                                <h4 class="panel-title">
                                                                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $ons ?>" aria-expanded="false" aria-controls="collapse<?php echo $ons ?>"><?php the_sub_field('article_title');?></a>
                                                                </h4>
                                                            </div>
                                                            <div id="collapse<?php echo $ons ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading<?php echo $ons ?>">
                                                                <div class="panel-body">
                                                                    <?php the_sub_field('article_body');?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php endif; ?>
                                            <?php $ons++; endwhile; ?>
                                        <?php endif; ?>
                                    </div>

                                    <div role="tabpanel" class="tab-pane" id="spanish">
                                        <?php $ons=200; if(get_field('own_news')): ?>
                                            <?php while(has_sub_field('own_news')): ?>
                                                <?php if( get_sub_field('language') == 'Spanish' ): ?>
                                                    <strong>Published Date:</strong> <?php the_sub_field('publised_date');?>
                                                    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                                                        <div class="panel panel-default">
                                                            <div class="panel-heading" role="tab" id="heading<?php echo $ons ?>">
                                                                <h4 class="panel-title">
                                                                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $ons ?>" aria-expanded="false" aria-controls="collapse<?php echo $ons ?>"><?php the_sub_field('article_title');?></a>
                                                                </h4>
                                                            </div>
                                                            <div id="collapse<?php echo $ons ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading<?php echo $ons ?>">
                                                                <div class="panel-body">
                                                                    <?php the_sub_field('article_body');?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php endif; ?>
                                            <?php $ons++; endwhile; ?>
                                        <?php endif; ?>
                                    </div>
                                </div>