Home Forums Basel support forum Adding Page Title Section to Custom Post Type Created by Plugin

Adding Page Title Section to Custom Post Type Created by Plugin

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #19722

    robertarrow
    Participant

    I’m using the Events Calendar Pro plugin and it allows me to change the template files, but I can’t figure out how to add the following information from the meta box to the top of the page.

    <div class="page-title page-title-default title-size-small color-scheme-light title-design-centered" style="background-image: url(https://btcboca.org/wp-content/uploads/2015/07/About-Us-Header-Image.jpg);"> <div class="container"> <header class="entry-header"> <h1 class="entry-title">About Us</h1> <div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#"><a href="https://btcboca.org/" rel="v:url" property="v:title">Home</a> ยป <span class="current">About Us</span></div><!-- .breadcrumbs --> </header><!-- .entry-header --> </div> </div>

    I looked at this post and changed the functions.php file in my child theme and I see the metabox in the backend of the events post type, but I’m not sure what I should add to the template files to allow that information to be pulled from the metaboxes (CMB2) to the frontend of the post type. Any help would be greatly appreciated. Thanks!

    #19723

    robertarrow
    Participant

    These are the templates it came with…

    default-template.php

    <?php
    /**
     * Default Events Template
     * This file is the basic wrapper template for all the views if 'Default Events Template'
     * is selected in Events -> Settings -> Template -> Events Template.
     *
     * Override this template in your own theme by creating a file at [your-theme]/tribe-events/default-template.php
     *
     * @package TribeEventsCalendar
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    get_header();
    ?>
    <div id="tribe-events-pg-template" class="tribe-events-pg-template">
    	<?php tribe_events_before_html(); ?>
    	<?php tribe_get_view(); ?>
    	<?php tribe_events_after_html(); ?>
    </div> <!-- #tribe-events-pg-template -->
    <?php
    get_footer();

    single-event.php

    <?php
    /**
     * Single Event Template
     * A single event. This displays the event title, description, meta, and
     * optionally, the Google map for the event.
     *
     * Override this template in your own theme by creating a file at [your-theme]/tribe-events/single-event.php
     *
     * @package TribeEventsCalendar
     * @version  4.3
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    $events_label_singular = tribe_get_event_label_singular();
    $events_label_plural = tribe_get_event_label_plural();
    
    $event_id = get_the_ID();
    
    ?>
    
    <div id="tribe-events-content" class="tribe-events-single">
    
    	<p class="tribe-events-back">
    		<a href="<?php echo esc_url( tribe_get_events_link() ); ?>"> <?php printf( '&laquo; ' . esc_html_x( 'All %s', '%s Events plural label', 'the-events-calendar' ), $events_label_plural ); ?></a>
    	</p>
    
    	<!-- Notices -->
    	<?php tribe_the_notices() ?>
    
    	<?php the_title( '<h1 class="tribe-events-single-event-title">', '</h1>' ); ?>
    
    	<div class="tribe-events-schedule tribe-clearfix">
    		<?php echo tribe_events_event_schedule_details( $event_id, '<h2>', '</h2>' ); ?>
    		<?php if ( tribe_get_cost() ) : ?>
    			<span class="tribe-events-cost"><?php echo tribe_get_cost( null, true ) ?></span>
    		<?php endif; ?>
    	</div>
    
    	<!-- Event header -->
    	<div id="tribe-events-header" <?php tribe_events_the_header_attributes() ?>>
    		<!-- Navigation -->
    		<h3 class="tribe-events-visuallyhidden"><?php printf( esc_html__( '%s Navigation', 'the-events-calendar' ), $events_label_singular ); ?></h3>
    		<ul class="tribe-events-sub-nav">
    			<li class="tribe-events-nav-previous"><?php tribe_the_prev_event_link( '<span>&laquo;</span> %title%' ) ?></li>
    			<li class="tribe-events-nav-next"><?php tribe_the_next_event_link( '%title% <span>&raquo;</span>' ) ?></li>
    		</ul>
    		<!-- .tribe-events-sub-nav -->
    	</div>
    	<!-- #tribe-events-header -->
    
    	<?php while ( have_posts() ) :  the_post(); ?>
    		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    			<!-- Event featured image, but exclude link -->
    			<?php echo tribe_event_featured_image( $event_id, 'full', false ); ?>
    
    			<!-- Event content -->
    			<?php do_action( 'tribe_events_single_event_before_the_content' ) ?>
    			<div class="tribe-events-single-event-description tribe-events-content">
    				<?php the_content(); ?>
    			</div>
    			<!-- .tribe-events-single-event-description -->
    			<?php do_action( 'tribe_events_single_event_after_the_content' ) ?>
    
    			<!-- Event meta -->
    			<?php do_action( 'tribe_events_single_event_before_the_meta' ) ?>
    			<?php tribe_get_template_part( 'modules/meta' ); ?>
    			<?php do_action( 'tribe_events_single_event_after_the_meta' ) ?>
    		</div> <!-- #post-x -->
    		<?php if ( get_post_type() == Tribe__Events__Main::POSTTYPE && tribe_get_option( 'showComments', false ) ) comments_template() ?>
    	<?php endwhile; ?>
    
    	<!-- Event footer -->
    	<div id="tribe-events-footer">
    		<!-- Navigation -->
    		<h3 class="tribe-events-visuallyhidden"><?php printf( esc_html__( '%s Navigation', 'the-events-calendar' ), $events_label_singular ); ?></h3>
    		<ul class="tribe-events-sub-nav">
    			<li class="tribe-events-nav-previous"><?php tribe_the_prev_event_link( '<span>&laquo;</span> %title%' ) ?></li>
    			<li class="tribe-events-nav-next"><?php tribe_the_next_event_link( '%title% <span>&raquo;</span>' ) ?></li>
    		</ul>
    		<!-- .tribe-events-sub-nav -->
    	</div>
    	<!-- #tribe-events-footer -->
    
    </div><!-- #tribe-events-content -->
    
    #19727

    Artem Temos
    Keymaster

    Hi,

    Sorry, but your question is not quite clear for us. What metabox you are asking for and where do you want to display it?

    Regards

    #19751

    robertarrow
    Participant

    Sorry if my question was confusing, I’ll comment back in my process so you can see how to best help me. My first step was adding the following function to my functions.php of my Basel Child Theme to allow this Page Setting (custom metabox from theme) to show.

    /**
     * Add metaboxesto pages and posts
     * uses CMB plugins
     * 
     */
    
    /*
        to fix image uploads for taxonomies
        add to file CMB2hookup.php
        line 197
        if ( in_array( $hook, array( 'edit-tags.php', 'post.php', 'post-new.php', 'page-new.php', 'page.php' ), true ) ) {
    
     */
    class BASEL_Metaboxes {
        /**
         * Options slug for Redux Framework
         * @var string
         */
    	private $opt_name = "basel_options";
    
        /**
         * Add actions
         * 
         */
    	public function __construct() {
    
    		//add_action( 'init', array( $this, 'load_cmb_plugin' ), 199 );
    
            add_action( 'cmb2_init', array( $this, 'load_cmb_plugin' ), 199 );
            add_action( 'cmb2_init', array( $this, 'pages_metaboxes' ), 5000 );
            add_action( 'cmb2_init', array( $this, 'product_metaboxes' ), 6000 );
            add_action( 'cmb2_init', array( $this, 'product_categories' ), 7000 );
            add_action( 'cmb2_init', array( $this, 'posts_categories' ), 8000 );
    
            add_action("redux/metaboxes/{$this->opt_name}/boxes", array( $this, 'metaboxes' ) );
    	}
    
        /**
         * Require CMB plugin files
         * 
         */
    	public function load_cmb_plugin() {
            // Deprecated from BASEL 3.0
    		if ( ! basel_new_meta() && function_exists( 'new_cmb2_box' ) ) {
    			require_once( apply_filters('basel_require', BASEL_3D . '/Taxonomy_MetaData/Taxonomy_MetaData_CMB2.php' ) );
    		}
    	}
    
        /**
         * Register all custom metaboxes with CMB2 API
         */
        public function pages_metaboxes() {
            global $basel_transfer_options, $basel_prefix;
    
            // Start with an underscore to hide fields from custom fields list
            $basel_prefix = '_basel_';
            
            $basel_metaboxes = new_cmb2_box( array(
                // 'cmb_styles' => false, // false to disable the CMB stylesheet
                // 'closed'     => true, // true to keep the metabox closed by default
                'id' => 'page_metabox',
                'title' => 'Page Setting (custom metabox from theme)',
                'object_types' => array('page', 'post', 'portfolio', 'tribe_events'), // post type
                'context' => 'normal',
                'priority' => 'high',
                'show_names' => true, // Show field names on the left
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Custom sidebar for this page',
                'id'      => $basel_prefix . 'custom_sidebar',
                'type'    => 'select',
                'options' => basel_get_sidebars_array()
            ) );
    
            $basel_transfer_options = array( 
                'main_layout',
                'sidebar_width',
                'header',
                'header-overlap',
                'header_color_scheme',
                'page-title-size',
            );
    
            foreach ($basel_transfer_options as $field) {
                $cmb_field = $this->redux2cmb_field( $field );
                $basel_metaboxes->add_field( $cmb_field );
            }
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Disable Page title',
                'desc'    => 'You can hide page heading for this page',
                'id'      => $basel_prefix . 'title_off',
                'type'    => 'checkbox',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name' => 'Image for page heading',
                'desc' => 'Upload an image',
                'id' => $basel_prefix . 'title_image',
                'type' => 'file',
                'allow' => array( 'url', 'attachment' ) // limit to just attachments with array( 'attachment' )
            ) );
    
            $basel_metaboxes->add_field( array(
                'name' => 'Page heading background color',
                'desc' => 'Upload an image',
                'id' => $basel_prefix . 'title_bg_color',
                'type' => 'colorpicker',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Text color for heading',
                'id'      => $basel_prefix . 'title_color',
                'type'    => 'radio_inline',
                'options' => array(
                    'default' => __( 'Inherit', 'basel' ),
                    'light' => 'Light', 
                    'dark' => 'Dark',
                ),
                'default' => 'default'
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Open categories menu',
                'desc'    => 'Always shows categories navigation on this page',
                'id'      => $basel_prefix . 'open_categories',
                'type'    => 'checkbox',
            ) );
        }
    
        /**
         * Metaboxes for products
         */
        public function product_metaboxes() {
            global $basel_prefix, $basel_transfer_options;
    
            // Start with an underscore to hide fields from custom fields list
            $basel_prefix = '_basel_';
            $taxonomies_list = array( '' => 'Select' );
            $taxonomies = get_taxonomies(); 
            foreach ( $taxonomies as $taxonomy ) {
                $taxonomies_list[$taxonomy] = $taxonomy;
            }
    
            $basel_metaboxes = new_cmb2_box( array(
                // 'cmb_styles' => false, // false to disable the CMB stylesheet
                // 'closed'     => true, // true to keep the metabox closed by default
                'id' => 'product_metabox',
                'title' => 'Product Setting (custom metabox from theme)',
                'object_types' => array('product'), // post type
                'context' => 'normal',
                'priority' => 'high',
                'show_names' => true, // Show field names on the left
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => esc_html__('Add "New" label', 'basel'), 
                'desc'    => 'You can add "New" label to this product',
                'id'      => $basel_prefix . 'new_label',
                'type'    => 'checkbox',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Hide related products',
                'desc'    => 'You can hide related products on this page',
                'id'      => $basel_prefix . 'related_off',
                'type'    => 'checkbox',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => __('Hide tabs headings', 'basel'), 
                'desc'    => 'Description and Additional information',
                'id'      => $basel_prefix . 'hide_tabs_titles',
                'type'    => 'checkbox',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => __('Grid swatch attribute to display', 'basel'), 
                'desc' => __('Choose attribute that will be shown on products grid for this particular product', 'basel'),
                'id'      => $basel_prefix . 'swatches_attribute',
                'type'    => 'select',
                'options' => $taxonomies_list
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => __('Product video URL', 'basel'), 
                'desc'    => 'Vimeo or YouTube video url. For example: https://www.youtube.com/watch?v=1zPYW6Ipgok',
                'id'      => $basel_prefix . 'product_video',
                'type'    => 'text',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => __('Instagram product hashtag', 'basel'), 
                'desc'    => 'Insert tag that will be used to display images from instagram from your customers. For example: <strong>#nike_rush_run</strong>',
                'id'      => $basel_prefix . 'product_hashtag',
                'type'    => 'text',
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => __('Product background', 'basel'), 
                'id'      => $basel_prefix . 'product-background',
                'type'    => 'colorpicker',
            ) );
    
            $basel_local_transfer_options = array( 
                'single_product_style',
                'product_design',
                'main_layout',
                'sidebar_width',
            );
    
            foreach ($basel_local_transfer_options as $field) {
                $cmb_field = $this->redux2cmb_field( $field );
                $basel_metaboxes->add_field( $cmb_field );
            }
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Custom sidebar for this product',
                'id'      => $basel_prefix . 'custom_sidebar',
                'type'    => 'select',
                'options' => basel_get_sidebars_array()
            ) );
    
            $blocks = array_flip(basel_get_static_blocks_array());
    
            $blocks = (array)'None' + $blocks;
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Extra content block',
                'desc'    => 'You can create some extra content with Visual Composer (in Admin panel / HTML Blocks / Add new) and add it to this product',
                'id'      => $basel_prefix . 'extra_content',
                'type'    => 'select',
                'options' => $blocks
            ) );
    
            $basel_metaboxes->add_field( array(
                'name'    => 'Extra content position',
                'id'      => $basel_prefix . 'extra_position',
                'type'    => 'radio_inline',
                'options' => array(
                    'after' => __( 'After content', 'basel' ),
                    'before' => __( 'Before content', 'basel' ),
                    'prefooter' => __( 'Prefooter', 'basel' ),
                ),
                'default' => 'after'
            ) );
    
            $basel_transfer_options = array_merge( $basel_transfer_options, $basel_local_transfer_options );
            
        }
    
        public function posts_categories() {
    
            $blog_design_field = $this->redux2cmb_field( 'blog_design' );
    
            $blog_design_field['name'] .= ' for this category';
    
            if( basel_new_meta() ) {
                $cmb_term = cmb2_get_metabox( array(
                    'id'               => 'cat_options',
                    'object_types'     => array( 'term' ), 
                    'taxonomies'       => array( 'category' ), 
                    'new_term_section' => true, // Will display in the "Add New Category" section
                ), basel_get_current_term_id(), 'term' );
    
                $cmb_term->add_field($blog_design_field);
            } else {
                $posts_cat_metaboxes = array(
                    'id'         => 'cat_options',
                    // 'key' and 'value' should be exactly as follows
                    'show_on'    => array( 'key' => 'options-page', 'value' => array( 'unknown', ), ),
                    'show_names' => true, // Show field names on the left
                    'fields'     => array(
                        $blog_design_field
                    )
                );
    
                /**
                 * Instantiate our taxonomy meta class
                 */
                $cats = new Taxonomy_MetaData_CMB2( 'category', $posts_cat_metaboxes, __( 'Category Settings', 'taxonomy-metadata' ) );     
            }
    
        }
    
        public function product_categories() {
            $field = array(
                        'name' => 'Image for category heading',
                        'desc' => 'Upload an image',
                        'id' => 'title_image',
                        'type' => 'file',
                        'allow' => array( 'url', 'attachment' ) // limit to just attachments with array( 'attachment' )
                    );
    
            if( basel_new_meta() ) {
                $cmb_term = cmb2_get_metabox( array(
                    'id'               => 'product_cat_options',
                    'object_types'     => array( 'term' ), 
                    'taxonomies'       => array( 'product_cat' ), 
                    'new_term_section' => true, // Will display in the "Add New Category" section
                ), basel_get_current_term_id(), 'term' );
    
                $cmb_term->add_field($field);
            } else {
                $product_cat_metaboxes = array(
                    'id'         => 'cat_options',
                    // 'key' and 'value' should be exactly as follows
                    'show_on'    => array( 'key' => 'options-page', 'value' => array( 'unknown', ), ),
                    'show_names' => true, // Show field names on the left
                    'fields'     => array(
                        $field
                    )
                );
    
                /**
                 * Instantiate our taxonomy meta class
                 */
                $cats = new Taxonomy_MetaData_CMB2( 'product_cat', $product_cat_metaboxes, __( 'Category Settings', 'taxonomy-metadata' ) );  
            }
    
        }
    
        /**
         * Transfer function from redux to CMB2
         * @param  string $field      field slug in Redux options
         * @return array  $cmb_field  CMB compatible field config array
         */
    	public function redux2cmb_field( $field ) {
    
            if( ! class_exists('Redux') ) return array(
                'id' => '',
                'type' => '',
                'name' => '',
                'options' => '',
                'default' => 'default'  ,
            );
    
    		$prefix = '_basel_';
    
    		$field = Redux::getField($this->opt_name, $field);
    
    		$options = array();
    		
    		switch ($field['type']) {
    			case 'image_select':
    				$type = 'select';
    				$options = ( ! empty( $field['options'] ) ) ? array_merge( array('default' => array('title' => 'Inherit') ), $field['options'] ) : array();
    				foreach ($options as $key => $option) {
    					$options[$key] = ( isset( $options[$key]['alt'] ) ) ? $options[$key]['alt'] : $options[$key]['title'];
    				}
    			break;
    
    			case 'button_set':
    				$type = 'radio_inline';
    				$options['default'] = 'Inherit';
    				foreach ($field['options'] as $key => $value) {
    					$options[$key] = $value;
    				}
    			break;
    
                case 'select':
                    $type = 'select';
                    $options['inherit'] = 'Inherit';
                    foreach ($field['options'] as $key => $value) {
                        $options[$key] = $value;
                    }
                break;
    
                case 'switch':
                    $type = 'checkbox';
                break;
    			
    			default:
    				$type = $field['type'];
    			break;
    		}
    
    		$cmb_field = array(
    			'id' => $prefix . $field['id'],
    			'type' => $type,
    			'name' => $field['title'],
    			'options' => $options,
    		);
    
    		return $cmb_field;
    	}
    
        public function metaboxes($metaboxes) {
            // Declare your sections
            $boxSections = array();
            $boxSections[] = array(
                'title' => 'Performance',
                'id' => 'performance',
                'icon' => 'el-icon-cog',
                'fields' => array (
                    array (         
                        'id'       => 'product-background',
                        'type'     => 'background',
                        'title'    => __('Product background', 'basel'),
                        'subtitle' => __('Set background for your products page. You can also specify different background for particular products while editing it.', 'basel'),
                        'output'   => array('.single-product-content')
                    ),
                ),
            );
     
            // Declare your metaboxes
            $metaboxes = array();
            $metaboxes[] = array(
                'id'            => 'sidebar',
                'title'         => __( 'Sidebar', 'basel' ),
                'post_types'    => array( 'product' ),
                //'page_template' => array('page-test.php'), // Visibility of box based on page template selector
                //'post_format' => array('image'), // Visibility of box based on post format
                'position'      => 'normal', // normal, advanced, side
                'priority'      => 'high', // high, core, default, low - Priorities of placement
                'sections'      => $boxSections,
            );
     
            return $metaboxes;
        }
    
    }
    #19752

    robertarrow
    Participant

    Adding this to the functions.php file allowed the custom metabox to show in the backend of WordPress in the custom post type added by this plugin. See attached screenshot named BACKEND EVENT POST TYPE. Unfortunately, when I set the options, nothing shows on the front end

    Attachments:
    You must be logged in to view attached files.
    #19767

    robertarrow
    Participant

    Continued… Unfortunately, when I set the options, nothing shows on the front end of this post. (See FRONTEND EVENT POST TYPE screenshot). In the theme settings, I can select from a few different Page Templates. (See PAGE TEMPLATES FOR EVENTS screenshot).

    Even when selecting the Default Page Template, nothing shows on the frontend. So my question is… Where do I find the elements that generate the Page Title, Heading & Background so that I can add them to the DEFAULT EVENTS TEMPLATE that they have provided for me. I understand if they need to be rewritten somehow, but if you could point me in the right direction that would be great as I would have my developer help me.

    Attachments:
    You must be logged in to view attached files.
    #19773

    Artem Temos
    Keymaster

    Hi,

    Adding these meta boxes to the backend is not enough and you will need to code their usages on the frontend too. Sorry, but we don’t have an instruction for this. As for the page heading, so you can find appropriate PHP functions in the file inc/template-tags.php.

    Regards

    #19774

    robertarrow
    Participant

    Okay, so basically, I just need to edit my functions.php in my Child Theme to allow events to show a page title in a similar manner while using the default page template instead of the events page template?

    #19776

    Artem Temos
    Keymaster

    Sorry, but we can’t know where do you need to place the page title function to display it on the event page. We are not aware of the plugin code structure and template organization.

Viewing 9 posts - 1 through 9 (of 9 total)