Witam,

zastanawiam się czy wydajnym rozwiązaniem będzie generowanie htmla w pętli w szablonie dla WORDPRESSA w zależności od tego czy dany widget/sidebar jest używany

  1. $positions = array("top", "header", "navigation", "showcase", "feature", "maintop", "mainbottom", "bottom", "footer", "copyright");
  2.  
  3. foreach ($positions as $position) {
  4. if ( (is_active_sidebar(''.$position.'_left')) or (is_active_sidebar(''.$position.'_center')) or (is_active_sidebar(''.$position.'_right')) ) : ?>
  5. <div id="<?php echo $position ?>">
  6. <div class="container-fluid section-wrapper">
  7. <div class="row">
  8.  
  9. <?php if ( (is_active_sidebar(''.$position.'_left')) and (is_active_sidebar(''.$position.'_right')) ) : ?>
  10. <div class="col-md-3 col-sm-12 col-xs-12 top-left"><?php dynamic_sidebar( ''.$position.'_left' ); ?></div>
  11. <div class="col-md-6 col-sm-12 col-xs-12 top-center"><?php dynamic_sidebar( ''.$position.'_center' ); ?></div>
  12. <div class="col-md-3 col-sm-12 col-xs-12 top-right"><?php dynamic_sidebar( ''.$position.'_right' ); ?></div>
  13.  
  14.  
  15. <?php endif;?>
  16.  
  17. </div>
  18. </div>
  19. </div>
  20. <?php endif;?>
  21. <?php } ?>


oraz czy w ogóle można pomyśleć o dynamicznym rejestrowaniu sidebarów:

  1. function my_register_sidebars() {
  2.  
  3. $sidebars = array (
  4. array( "s_id" => "top",
  5. "s_name" => "TOP ",
  6. "s_description" => "Małe dodatki na górze strony - pozycja "
  7. ),
  8. array( "s_id" => "header",
  9. "s_name" => "HEADER ",
  10. "s_description" => "Nagłowek strony (logo, tekst powitalny, etc.) - pozycja "
  11. )
  12. );
  13.  
  14. foreach ($sidebars as $sidebar) {
  15.  
  16. $positions = array (
  17. array( "p_id" => "_left",
  18. "p_name" => "LEFT",
  19. "p_description" => "LEWA"
  20. ),
  21. array( "p_id" => "_center",
  22. "p_name" => "CENTER",
  23. "p_description" => "ŚRODKOWA"
  24. ),
  25. array( "p_id" => "_right",
  26. "p_name" => "RIGHT",
  27. "p_description" => "PRAWA"
  28. )
  29. );
  30.  
  31. foreach ($positions as $position) {
  32. register_sidebar (
  33. 'id' => $sidebar['s_id'].$position['p_id'],
  34. 'name' => __( $sidebar['s_name'].$position['p_name'] ),
  35. 'description' => __( $sidebar['s_description'].$position['p_description'] ),
  36. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  37. 'after_widget' => '</div>',
  38. 'before_title' => '<h3 class="widget-title">',
  39. 'after_title' => '</h3>'
  40. )
  41. );
  42. }
  43. }
  44. }


O ile dla htmla nie powinno to być za bardzo obciązające to generowanie co wywołanie strony tych sidebarów myślę że może być zabójcze dla serwera.

Co myślicie?