Drukowana wersja tematu

Kliknij tu, aby zobaczyć temat w orginalnym formacie

Forum PHP.pl _ Systemy portalowe i CMS'y _ [WORDPRESS] Dynamiczne generowanie i deklarowanie treści/sidebarów

Napisany przez: NetPax 29.06.2017, 12:59:31

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 http://www.php.net/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 = http://www.php.net/array (
  4. http://www.php.net/array( "s_id" => "top",
  5. "s_name" => "TOP ",
  6. "s_description" => "Małe dodatki na górze strony - pozycja "
  7. ),
  8. http://www.php.net/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 = http://www.php.net/array (
  17. http://www.php.net/array( "p_id" => "_left",
  18. "p_name" => "LEFT",
  19. "p_description" => "LEWA"
  20. ),
  21. http://www.php.net/array( "p_id" => "_center",
  22. "p_name" => "CENTER",
  23. "p_description" => "ŚRODKOWA"
  24. ),
  25. http://www.php.net/array( "p_id" => "_right",
  26. "p_name" => "RIGHT",
  27. "p_description" => "PRAWA"
  28. )
  29. );
  30.  
  31. foreach ($positions as $position) {
  32. register_sidebar (
  33. http://www.php.net/array(
  34. 'id' => $sidebar['s_id'].$position['p_id'],
  35. 'name' => __( $sidebar['s_name'].$position['p_name'] ),
  36. 'description' => __( $sidebar['s_description'].$position['p_description'] ),
  37. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  38. 'after_widget' => '</div>',
  39. 'before_title' => '<h3 class="widget-title">',
  40. 'after_title' => '</h3>'
  41. )
  42. );
  43. }
  44. }
  45. }


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?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)