Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'cmb2_admin_init', 'diabolo_home_page_listings' );
- function diabolo_home_page_listings() {
- $prefix = '_dp_';
- $cmb = new_cmb2_box( array(
- 'id' => $prefix . 'metaboxID',
- 'title' => 'Column 2 & 3 Settings',
- 'object_types' => array( 'page' ),
- 'context' => 'after_editor',
- 'show_names' => true,
- 'show_on_cb' => 'diabolo_show_cmb2_on_front_page',
- ) );
- $cmb->add_field( array(
- 'name' => 'Column 2 title',
- 'desc' => 'Enter the text to be shown above the posts in column 2.',
- //'default' => 'standard value (optional)',
- 'id' => $prefix . 'col2title',
- 'type' => 'text',
- ) );
- $cmb->add_field( array(
- 'id' => $prefix . 'col2category',
- 'type' => 'taxonomy_radio',
- 'taxonomy' => 'category',
- 'name' => 'Column 2 category',
- 'desc' => 'Select the category for posts in column 2',
- ) );
- $cmb->add_field( array(
- 'name' => 'Number of posts to show',
- 'desc' => 'Numbers only',
- 'id' => $prefix . 'col2count',
- 'type' => 'text',
- 'attributes' => array(
- 'type' => 'number',
- 'pattern' => '\d*',
- ),
- ) );
- $cmb->add_field( array(
- 'name' => 'Column 3 title',
- 'desc' => 'Enter the text to be shown above the posts in column 3.',
- //'default' => 'standard value (optional)',
- 'id' => $prefix . 'col3title',
- 'type' => 'text',
- ) );
- $cmb->add_field( array(
- 'id' => $prefix . 'col3category',
- 'type' => 'taxonomy_select',
- 'taxonomy' => 'category',
- 'name' => 'Column 3 category',
- 'desc' => 'Select the category for posts in column 3',
- ) );
- $cmb->add_field( array(
- 'name' => 'Number of posts to show',
- 'desc' => 'Numbers only',
- 'id' => $prefix . 'col3count',
- 'type' => 'text',
- 'attributes' => array(
- 'type' => 'number',
- 'pattern' => '\d*',
- ),
- ) );
- }
- function diabolo_show_cmb2_on_front_page( $cmb ) {
- //error_log( "CMB: ".var_export( $cmb, true ) );
- // Extracted from: https://github.com/CMB2/CMB2/wiki/Adding-your-own-show_on-filters#example-front-page-show_on-filter
- $post_id = 0;
- // If we're showing it based on ID, get the current ID
- if ( isset( $_GET['post'] ) ) {
- $post_id = $_GET['post'];
- } elseif ( isset( $_POST['post_ID'] ) ) {
- $post_id = $_POST['post_ID'];
- }
- if ( ! $post_id ) {
- return false;
- }
- // Get ID of page set as front page, 0 if there isn't one
- $front_page = get_option( 'page_on_front' );
- // There is a front page set and we're on it!
- return $post_id == $front_page;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement