php - How to set "class = active" for second tab? -


i have tabs. in first tab "introduction" , "outline" first tab. have set introduction class=active when comes first. when outline comes first not getting how set class active.

code below

<ul class="nav-tabs" role="tablist">     <?php      $tabs = array();     if(!$sessid == "" && !$checkcourse){         $tabs = array("introduction"=>true, "outline"=>true,"announcement"=>false,"discussion"=>false,"review"=>true, "student"=>true, "comment"=>true);      } else if($sessid == "") {         $tabs = array("introduction"=>true, "outline"=>true,"announcement"=>false,"discussion"=>false,"review"=>true, "student"=>false, "comment"=>true);      } else {         $tabs = array("introduction"=>false, "outline"=>true,"announcement"=>true,"discussion"=>true,"review"=>true, "student"=>true, "comment"=>false);      }     ?>                                    <?php if($tabs['introduction']) { ?>         <li class="active"><a href="#introduction" role="tab" data-toggle="tab">introduction</a></li>     <?php } ?>     <?php if($tabs['outline']) { ?>         <li><a href="#outline" role="tab" data-toggle="tab">outline</a></li>     <?php } ?>     <?php if($tabs['review']) { ?>         <li><a href="#review" role="tab" data-toggle="tab">review</a></li>     <?php } ?>     <?php if($tabs['student']) { ?>         <li><a href="#student" role="tab" data-toggle="tab">student</a></li>     <?php } ?>     <?php if($tabs['comment']) { ?>         <li><a href="#comment" role="tab" data-toggle="tab">comment</a></li>     <?php } ?>     <?php if($tabs['announcement']) { ?>         <li><a href="#announcement" role="tab" data-toggle="tab">announcement</a></li>     <?php } ?>     <?php if($tabs['discussion']) { ?>         <li><a href="#discussion" role="tab" data-toggle="tab">discussion</a></li>     <?php } ?>                   </ul> 

simple check ternary operator is:

<?php if($tabs['outline']) {?>     <li <?=$tabs['introduction']? '' : ' class="active"';?>><a href="#outline" role="tab" data-toggle="tab">outline</a></li> <?php } ?> 

so check if $tabs['introduction'] isset don't need class="active", else - add class.

update: first item of tab can change, advise create simple foreach:

$is_first = true; foreach ($tabs $tab_name => $value) {     if ($value) {         echo '<li' . ($is_first? ' class="active"' : '') . '><a href="#' . $tab_name . '" role="tab" data-toggle="tab">' . $tab_name . '</a></li>';         $is_first = false;  // fix have first value here     } } 

here main problem how link href value , caption.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -