nazim259

Untitled

Apr 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1.  
  2. **************************************************** metabox and options.php *****************************************
  3.  
  4. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
  5.  
  6.  
  7.  
  8. function factorian_theme_metabox($options){
  9.  
  10. $options = array(); // remove old options
  11.  
  12.  
  13.  
  14. $options[] = array(
  15. 'id' => 'fac_page_options',
  16. 'title' => 'Page Options',
  17. 'post_type' => 'page',
  18. 'context' => 'normal',
  19. 'priority' => 'high',
  20. 'sections' => array(
  21.  
  22. // begin: a section
  23. array(
  24. 'name' => 'factorian_page_options_meta',
  25. 'icon' => 'fa fa-cog',
  26.  
  27. // begin: fields
  28. 'fields' => array(
  29.  
  30. // begin: a field
  31. array(
  32. 'id' => 'enable_title',
  33. 'type' => 'switcher',
  34. 'title' => 'Enable Title?',
  35. 'default' => true,
  36. 'desc' => esc_html__('If you want to enable title, select yes.','mytheme'),
  37. ),
  38. array(
  39. 'id' => 'enable_content',
  40. 'type' => 'switcher',
  41. 'title' => 'Enable content?',
  42. 'default' => true,
  43. 'desc' => esc_html__('If you want to enable content, select yes.','mytheme'),
  44. ),
  45.  
  46.  
  47. ),
  48.  
  49. )
  50. ),
  51. );
  52.  
  53.  
  54. return $options;
  55.  
  56.  
  57. }
  58. add_filter( 'cs_metabox_options', 'factorian_theme_metabox' );
  59.  
  60.  
  61. ********************************************************** content-page.php ***********************************************
  62.  
  63. <?php
  64. /**
  65. * Template part for displaying page content in page.php
  66. *
  67. * @link https://codex.wordpress.org/Template_Hierarchy
  68. *
  69. * @package mytheme
  70. */
  71.  
  72. if (get_post_meta($post->ID, 'fac_page_options', true)) {
  73. $page_meta = get_post_meta($post->ID, 'fac_page_options', true);
  74. }else{
  75. $page_meta = array();
  76. }
  77.  
  78.  
  79. if (array_key_exists('enable_title',$page_meta)) {
  80. $enable_title = $page_meta['enable_title'];
  81. }else{
  82. $enable_title = true;
  83. }
  84.  
  85.  
  86. if (array_key_exists('enable_content',$page_meta)) {
  87. $enable_content = $page_meta['enable_content'];
  88. }else{
  89. $enable_content = false;
  90. }
  91.  
  92.  
  93. ?>
  94.  
  95. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  96.  
  97. <?php if($enable_title==true) : ?>
  98. <header class="entry-header">
  99. <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
  100. </header><!-- .entry-header -->
  101. <?php endif; ?>
  102. <div class="entry-content">
  103. <?php
  104.  
  105. if($enable_content = true){
  106. the_content();
  107. }
  108.  
  109.  
  110. wp_link_pages( array(
  111. 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'mytheme' ),
  112. 'after' => '</div>',
  113. ) );
  114. ?>
Add Comment
Please, Sign In to add comment