Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. function componify(){
  4. if( function_exists( 'have_rows' ) && have_rows( 'components' ) ){
  5. while( have_rows( 'components') ){
  6. the_row();
  7. $type = classify( get_row_layout() );
  8. $content = buffer_template_part( 'components/component', $type );
  9. $content = preg_replace_callback( '/<h2(.*)?>(.*)?<\/h2>/', function($matches){
  10. return '<h2 id="to-'.classify( $matches[2] ).'" '.$matches[1].'>'.$matches[2].'</h2>';
  11. }, $content );
  12. ?>
  13. <section class="component component--<?= $type ; ?>">
  14. <?= $content ?>
  15. </section>
  16. <?php
  17. }
  18. }
  19. }
  20.  
  21. // you’ll need buffer_template_part() to make it work
  22. function buffer_template_part( $slug, $name ){
  23. ob_start();
  24. get_template_part( $slug, $name );
  25. return ob_get_clean();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement