Skip to content

Instantly share code, notes, and snippets.

@albionselimaj
Last active November 6, 2017 14:00
Show Gist options
  • Save albionselimaj/8e14631e7c94a3e2ce16caf104dedbe0 to your computer and use it in GitHub Desktop.
Save albionselimaj/8e14631e7c94a3e2ce16caf104dedbe0 to your computer and use it in GitHub Desktop.
Add custom content blocks
<?php
/*
* my-listing-child/functions.php
*/
add_filter( 'case27/listingtypes/profile_layout_blocks', function( $blocks ) {
$blocks[] = [
'type' => 'block_name', // needs to be something unique
'icon' => 'view_headline', // from material-icons list
'title' => 'Block Title',
'title_l10n' => ['locale' => 'en_US'], // work in progress for multilanguage support, just leave it like this
'show_field' => '',
'allowed_fields' => ['text', 'textarea','url', 'number'],
];
return $blocks;
});
add_action( 'case27/listing/blocks/block_name', function( $widget ) {
global $post;
// In the child theme, create sections/block-name.php
c27()->get_section('block-name', [
'ref' => 'single-listing', // just leave it like this
'icon' => 'material-icons://view_headline',
'title' => $widget['title'],
'some-field' => get_post_meta( $post->ID, "_{$widget['show_field']}", true ),
]);
});
?>
/*
* my-listing-child/sections/block-name.php
*/
<?php
$data = c27()->merge_options([
'some-field' => '', // The value of a field provided by the user
'icon' => '',
'icon_style' => 1,
'title' => '',
], $data);
// Validate field value.
if ( ! trim( $data['some-field'] ) ) {
return false;
}
?>
<div class="col-md-6 col-sm-12 col-xs-12 grid-item">
<div class="element content-block">
<div class="pf-head">
<div class="title-style-1 title-style-<?php echo esc_attr( $data['icon_style'] ) ?>">
<?php if ($data['icon_style'] != 3): ?>
<?php echo c27()->get_icon_markup($data['icon']) ?>
<?php endif ?>
<h5><?php echo esc_html( $data['title'] ) ?></h5>
</div>
</div>
<div class="pf-body">
<?php echo do_shortcode( "[shortcode_name some-field="{$data['some-field']}"]" ); ?>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment