Skip to content

Instantly share code, notes, and snippets.

@tinothepro
Created June 21, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinothepro/d43611ae20c307b30a4c72c1f52fd023 to your computer and use it in GitHub Desktop.
Save tinothepro/d43611ae20c307b30a4c72c1f52fd023 to your computer and use it in GitHub Desktop.
Content Section Template
<?php
Container::make('post_meta', 'WPD Layout Builder')
->show_on_post_type(array('page', 'portfolio'))
->add_fields(array(
Field::make('complex', 'sections', 'Sections')
->setup_labels($section_labels)
->set_layout('tabbed-vertical')
// Begin Content Section
->add_fields('Content Section', array(
Field::make('text', 'content_section_text', 'Title')
->set_width(80),
Field::make('checkbox', 'content_section_title_center', 'Center')
->set_width(20),
Field::make('radio', 'content_section_columns', 'Columns')
->add_options(array(
'1' => '1',
'2' => '2',
'3' => '3'
))
->set_default_value('1'),
Field::make('rich_text', 'content_section_column1', 'Column 1'),
Field::make('rich_text', 'content_section_column2', 'Column 2')
->set_conditional_logic(array(
'relation' => 'AND',
array(
'field' => 'content_section_columns',
'value' => '2',
'compare' => '>=',
)
)),
Field::make('rich_text', 'content_section_column3', 'Column 3')
->set_conditional_logic(array(
'relation' => 'AND',
array(
'field' => 'content_section_columns',
'value' => '3',
'compare' => '=',
)
)),.......
<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;
function content_section($section) {
$title = $section['content_section_text'];
$center_title = $section['content_section_title_center'];
$column1 = $section['content_section_column1'];
$column2 = $section['content_section_column2'];
$column3 = $section['content_section_column3'];
$column = $section['content_section_columns'];
$scheme = $section['content_section_color_scheme'];
$bg_color = $section['content_section_background_color'];
$drop_padding = $section['content_section_padding'];
$css_class = $section['content_section_css'];
$hide_on = $section['content_section_hide_on'];
if ($center_title) {
$center = 'centered';
} else {
$center = '';
}
if ($scheme == 'dark') {
$color = 'dark';
} else {
$color = 'light';
}
if ($bg_color) {
$style_bg = 'style="background-color: ' . $bg_color . ';"';
} else {
$style_bg = '';
}
if ($css_class) {
$css_class = $css_class;
} else {
$css_class = '';
}
$css = [];
array_push($css, $color, $css_class, $center);
if ($drop_padding) {
foreach( $drop_padding as $drop ) {
array_push($css, $drop);
}
}
if ($hide_on) {
foreach( $hide_on as $hidden ) {
array_push($css, $hidden);
}
}
$classes = rtrim(implode(' ', $css));
?>
<div class="column-section <?php echo $classes; ?>"<?php echo $style_bg; ?>>
<div class="wrap">
<?php if ($title) { ?>
<h2><?php echo $title; ?></h2>
<?php }
if ($column == 1) { ?>
<div class="single-column">
<?php echo carbon_content_parser($column1); ?>
</div>
<?php } elseif ($column == 2) { ?>
<div class="double-column">
<div class="first one-half">
<?php echo carbon_content_parser($column1); ?>
</div>
<div class="one-half">
<?php echo carbon_content_parser($column2); ?>
</div>
</div>
<?php } elseif ($column == 3) { ?>
<div class="triple-column">
<div class="first one-third">
<?php echo carbon_content_parser($column1); ?>
</div>
<div class="one-third">
<?php echo carbon_content_parser($column2); ?>
</div>
<div class="one-third">
<?php echo carbon_content_parser($column3); ?>
</div>
</div>
<?php } ?>
</div>
</div>
<?php }
<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;
add_action('carbon_register_fields', 'wpd_lb_register_section_types');
function wpd_lb_register_section_types() {
include_once(dirname(__FILE__) . '/includes/wpd-lb-page-meta.php');
}
function carbon_content_parser($meta_string) {
return apply_filters('the_content', $meta_string);
}
add_action('genesis_before_footer', 'carbon_builder', 1);
function carbon_builder() {
if (is_page() || is_single()) {
include_once(dirname(__FILE__) . '/output/content.php');
include_once(dirname(__FILE__) . '/output/content-image-split.php');
include_once(dirname(__FILE__) . '/output/small-column-with-image.php');
include_once(dirname(__FILE__) . '/output/image.php');
include_once(dirname(__FILE__) . '/output/full-width-image.php');
include_once(dirname(__FILE__) . '/output/side-by-side-images.php');
include_once(dirname(__FILE__) . '/output/parallax-image.php');
include_once(dirname(__FILE__) . '/output/short-testimonial.php');
include_once(dirname(__FILE__) . '/output/long-testimonial.php');
include_once(dirname(__FILE__) . '/output/call-to-action.php');
?>
<div id="wpd-layout-builder" class="wpd-lb">
<?php $sections = carbon_get_post_meta( get_the_ID(), 'sections', 'complex' ); ?>
<?php
if ($sections) {
foreach( $sections as $section ) { ?>
<?php
switch ($section['_type']) {
case '_content_section':
content_section($section);
break;
case '_small_column_with_image':
small_column_with_image($section);
break;
case '_image':
full_wrap_image_section($section);
break;
case '_full_width_image':
full_width_image($section);
break;
case '_side_by_side_images':
side_by_side_images($section);
break;
case '_parallax_image':
parallax_image($section);
break;
case '_short_testimonial':
short_testimonial($section);
break;
case '_long_testimonial':
long_testimonial($section);
break;
case '_call_to_action':
call_to_action($section);
break;
case '_content_and_image_split':
content_image_split($section);
break;
}
}
} ?>
</div>
<?php } // if post type
} // function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment