/** * Filters the 'theme_mods_theme_layout'. */ function tamatebako_set_post_layout($layout) { /* Only in front end singular */ if (!is_admin() && is_singular()) { /* Check if current post type has layouts support */ if (in_array(get_post_type(get_queried_object_id()), tamatebako_layouts_post_types())) { /* Get list of available layouts */ $layouts = array_keys(tamatebako_layouts()); /* Get current entry layout */ $post_layout = tamatebako_get_post_layout(get_queried_object_id()); /* If current entry has layout and the current layout is valid layout, use it. */ if (!empty($post_layout) && in_array($post_layout, $layouts)) { $layout = tamatebako_get_post_layout(get_queried_object_id()); } } } return $layout; }
/** * Filters the 'theme_mods_theme_layout'. */ function tamatebako_set_default_layout($layout) { /* Vars */ $layouts = array_keys(tamatebako_layouts()); $layouts_args = tamatebako_layouts_args(); /* If customizer enabled, use user set global layout. */ if (true === $layouts_args['customize']) { if (empty($layout)) { return tamatebako_layout_default(); } else { return $layout; } } else { return tamatebako_layout_default(); } }
/** * Render Content */ public function render_content() { /* Get theme layout args. */ $layouts_args = tamatebako_layouts_args(); $layouts = tamatebako_layouts(); /* No layout defined, return. */ if (empty($layouts)) { return; } /* Add default layout info in layout name */ $layouts[tamatebako_layout_default()]['name'] = $layouts[tamatebako_layout_default()]['name'] . ' (' . tamatebako_layouts_string('default') . ')'; /* Input name */ $name = '_customize-radio-' . $this->id; /* Wrapper class */ $wrap_class = 'customize-theme-layouts-wrap'; if (true == $layouts_args['thumbnail']) { $wrap_class .= ' theme-layouts-thumbnail-wrap'; } ?> <div class="<?php echo esc_attr($wrap_class); ?> "> <span class="customize-control-title"><?php echo esc_html(tamatebako_layouts_string('global_layout')); ?> </span> <?php foreach ($layouts as $layout => $layout_data) { /* Label class */ $label_class = "theme-layout-label"; if (tamatebako_layout_default() == $layout) { $label_class .= " layout-default"; } if (tamatebako_current_layout() == $layout) { $label_class .= " layout-selected"; } /* Label default */ $layout_label = $layout_data['name']; /* If theme using layout thumbnail, label using image. */ if (true == $layouts_args['thumbnail']) { $layout_label = '<img src="' . esc_url($layout_data['thumbnail']) . '" class="layout-thumbnail" title="' . esc_attr($layout_data['name']) . '">' . '<span class="layout-name">' . $layout_data['name'] . '</span>'; } ?> <label class="<?php echo esc_attr($label_class); ?> "> <input class="theme-layout-input" type="radio" value="<?php echo esc_attr($layout); ?> " name="<?php echo esc_attr($name); ?> " <?php $this->link(); checked($this->value(), $layout); ?> /> <?php echo $layout_label; ?> <br/> </label> <?php } // end foreach ?> </div><!-- .customize-theme-layouts-wrap --> <?php }
/** * Layout Meta Box Callback Function */ function tamatebako_layouts_post_meta_box($post, $box) { /* Vars */ $layouts_args = tamatebako_layouts_args(); $layouts = tamatebako_layouts(); /* Add Default/Global */ $layout_default = array(); if (true === $layouts_args['customize']) { $layout_default['default'] = array('name' => tamatebako_layouts_string('global_layout')); } else { $layout_default['default'] = array('name' => tamatebako_layouts_string('default')); } if (tamatebako_current_layout()) { $layout_default['default']['name'] = $layout_default['default']['name'] . ' (' . tamatebako_layout_name(tamatebako_current_layout()) . ')'; } $layouts = array_merge($layout_default, $layouts); /* Get current post/entry layout */ $post_layout = tamatebako_get_post_layout($post->ID); $div_class = 'post-layout'; if (true == $layouts_args['thumbnail']) { $div_class .= ' theme-layouts-thumbnail-wrap'; } if (!empty($post_layout)) { $div_class .= ' post-layout-selected'; } ?> <div id="post-layout" class="<?php echo esc_attr($div_class); ?> "> <?php wp_nonce_field(basename(__FILE__), 'theme-layouts-nonce'); ?> <div class="post-layout-wrap"> <?php foreach ($layouts as $layout => $layout_data) { /* Set empty value for Layout Global/Default */ $layout_value = $layout; if ('default' == $layout) { $layout_value = ''; } /* Label class */ $label_class = "theme-layout-label"; if ('default' == $layout) { $label_class .= " layout-default"; // hide it! } if ($post_layout == $layout) { $label_class .= " layout-selected"; } /* Label */ if (true === $layouts_args['customize']) { $layout_info = tamatebako_layouts_string('global_layout'); } else { $layout_info = tamatebako_layouts_string('default'); } if (tamatebako_current_layout() == $layout) { $layout_data['name'] = $layout_data['name'] . ' (' . $layout_info . ')'; $label_class .= " layout-global"; } $layout_label = $layout_data['name']; /* If theme using layout thumbnail, label using image. */ if (true == $layouts_args['thumbnail'] && isset($layout_data['thumbnail'])) { $layout_label = '<img src="' . esc_url($layout_data['thumbnail']) . '" class="layout-thumbnail" title="' . esc_attr($layout_data['name']) . '">' . '<span class="layout-name">' . $layout_data['name'] . '</span>'; } ?> <label style="display:block;" class="<?php echo esc_attr($label_class); ?> "> <input type="radio" name="post-layout" class="theme-layout-input" value="<?php echo esc_attr($layout_value); ?> " <?php checked($post_layout, $layout_value); ?> /> <?php echo $layout_label; ?> </label> <?php } // end foreach ?> </div> </div><?php }