Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **************************************************** metabox and options.php *****************************************
- <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
- function factorian_theme_metabox($options){
- $options = array(); // remove old options
- $options[] = array(
- 'id' => 'fac_page_options',
- 'title' => 'Page Options',
- 'post_type' => 'page',
- 'context' => 'normal',
- 'priority' => 'high',
- 'sections' => array(
- // begin: a section
- array(
- 'name' => 'factorian_page_options_meta',
- 'icon' => 'fa fa-cog',
- // begin: fields
- 'fields' => array(
- // begin: a field
- array(
- 'id' => 'enable_title',
- 'type' => 'switcher',
- 'title' => 'Enable Title?',
- 'default' => true,
- 'desc' => esc_html__('If you want to enable title, select yes.','mytheme'),
- ),
- array(
- 'id' => 'enable_content',
- 'type' => 'switcher',
- 'title' => 'Enable content?',
- 'default' => true,
- 'desc' => esc_html__('If you want to enable content, select yes.','mytheme'),
- ),
- ),
- )
- ),
- );
- return $options;
- }
- add_filter( 'cs_metabox_options', 'factorian_theme_metabox' );
- ********************************************************** content-page.php ***********************************************
- <?php
- /**
- * Template part for displaying page content in page.php
- *
- * @link https://codex.wordpress.org/Template_Hierarchy
- *
- * @package mytheme
- */
- if (get_post_meta($post->ID, 'fac_page_options', true)) {
- $page_meta = get_post_meta($post->ID, 'fac_page_options', true);
- }else{
- $page_meta = array();
- }
- if (array_key_exists('enable_title',$page_meta)) {
- $enable_title = $page_meta['enable_title'];
- }else{
- $enable_title = true;
- }
- if (array_key_exists('enable_content',$page_meta)) {
- $enable_content = $page_meta['enable_content'];
- }else{
- $enable_content = false;
- }
- ?>
- <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
- <?php if($enable_title==true) : ?>
- <header class="entry-header">
- <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
- </header><!-- .entry-header -->
- <?php endif; ?>
- <div class="entry-content">
- <?php
- if($enable_content = true){
- the_content();
- }
- wp_link_pages( array(
- 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'mytheme' ),
- 'after' => '</div>',
- ) );
- ?>
Add Comment
Please, Sign In to add comment