Skip to content

Instantly share code, notes, and snippets.

@grappler
Created June 24, 2016 17:51
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 grappler/067845cc9716e581be5ae930caec06d3 to your computer and use it in GitHub Desktop.
Save grappler/067845cc9716e581be5ae930caec06d3 to your computer and use it in GitHub Desktop.
<?php
function sc_menu( $atts, $content = null, $shortcode_tag = '' ) {
$bgcolors = array(
'blue' => array(
'class' => 'bg-cd-1',
'label' => __( 'Blue', 'prohelvetia' ),
),
'yellow' => array(
'class' => 'bg-cd-2',
'label' => __( 'Yellow', 'prohelvetia' ),
),
'lightgrey' => array(
'class' => 'bg-lightgrey',
'label' => __( 'Lightgrey', 'prohelvetia' ),
),
);
$a = shortcode_atts( array(
'the_title' => '',
'the_menu_title' => '',
'bgcolor' => '',
'menuposition' => 'frontpagedepartments',
), $atts, $shortcode_tag );
$bgcolor = array_key_exists( $a['bgcolor'], $bgcolors ) ? $this->bgcolors[ $a['bgcolor'] ]['class'] : '';
ob_start(); ?>
<section class="section <?php echo esc_attr( $bgcolor ); ?>">
<div class="wrap">
<?php if ( ! empty( $a['the_title'] ) ) : ?><h2><?php echo esc_html( $a['the_title'] ); ?></h2><?php endif; ?>
<div class="col-wrap">
<div class="col col-6">
<?php echo wp_kses_post( wpautop( $content ) ); ?>
</div>
<div class="col col-6">
<?php if ( ! empty( $a['the_title'] ) ) : ?>
<p><strong><?php echo esc_html( $a['the_menu_title'] ); ?></strong></p>
<?php endif; ?>
<?php wp_nav_menu( array(
'menu_class' => 'no-list inline-list category-tags',
'container' => false,
'theme_location' => $a['menuposition'],
) ); ?>
</div>
</div>
</div>
</section>
<?php wp_reset_postdata();
return ob_get_clean();
}
add_shortcode( 'ph_menu', 'sc_menu' );
function register_shortcode_ui_sc_menu() {
shortcode_ui_register_for_shortcode( 'ph_menu',
array(
'label' => esc_html__( 'Menu items as tags', 'prohelvetia' ),
'listItemImage' => 'dashicons-admin-post',
'post_type' => array( 'page' ),
'inner_content' => array(
'label' => esc_html__( 'Content', 'text-domain' ),
),
'attrs' => array(
array(
'label' => esc_html__( 'Title', 'text-domain' ),
'attr' => 'the_title',
'type' => 'text',
),
array(
'label' => esc_html__( 'Title above the menu items', 'text-domain' ),
'attr' => 'the_menu_title',
'type' => 'text',
),
array(
'label' => esc_html__( 'Menu', 'text-domain' ),
'attr' => 'menuposition',
'type' => 'select',
'options' => array(
'frontpagedepartments' => __( 'Frontpage departments menu', 'text-domain' ),
),
),
),
)
);
}
add_action( 'register_shortcode_ui', 'register_shortcode_ui_sc_menu' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment