Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function componify(){
- if( function_exists( 'have_rows' ) && have_rows( 'components' ) ){
- while( have_rows( 'components') ){
- the_row();
- $type = classify( get_row_layout() );
- $content = buffer_template_part( 'components/component', $type );
- $content = preg_replace_callback( '/<h2(.*)?>(.*)?<\/h2>/', function($matches){
- return '<h2 id="to-'.classify( $matches[2] ).'" '.$matches[1].'>'.$matches[2].'</h2>';
- }, $content );
- ?>
- <section class="component component--<?= $type ; ?>">
- <?= $content ?>
- </section>
- <?php
- }
- }
- }
- // you’ll need buffer_template_part() to make it work
- function buffer_template_part( $slug, $name ){
- ob_start();
- get_template_part( $slug, $name );
- return ob_get_clean();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement