Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Switch Theme
- Plugin URI:
- Description:
- Version:
- Author:
- Author URI:
- License:
- */
- if (is_admin()) :
- /* load plugin functions */
- add_action('add_meta_boxes', 'myplugin_add_meta_box');
- add_action('save_post', 'myplugin_save_meta_box');
- /* add meta box to page editing */
- function myplugin_add_meta_box() {
- add_meta_box('', 'Page Theme', 'myplugin_get_meta_box_contents', 'page', 'side', 'default', '');
- }
- /* meta box contents */
- function myplugin_get_meta_box_contents($post) {
- $themes = get_themes();
- $page_theme = get_post_meta($post->ID, 'page_theme', true);
- echo '<p><label for=page_theme><b>Themes:</b></label></p>';
- echo '<select name=page_theme>';
- echo '<option>(ohne)</option>';
- foreach($themes as $key => $theme) :
- $selected = ($themes[$key]["Template"] == $page_theme) ? 'selected' : '';
- echo '<option value="' . $themes[$key]['Template']. '"'. $selected .'>' . $themes[ $key ]['Name'] . ' </option>';
- endforeach;
- echo '</select>';
- }
- /* save theme options */
- function myplugin_save_meta_box($post_id) {
- update_post_meta($post_id, 'page_theme', $_POST['page_theme']);
- }
- endif;
- /* load page theme */
- add_filter('option_template', 'my_plugin_get_page_theme');
- add_filter('template', 'my_plugin_get_page_theme');
- add_filter('option_stylesheet', 'my_plugin_get_page_theme');
- function my_plugin_get_page_theme() {
- $page_id = get_the_ID();
- $page_theme = get_post_meta(get_the_ID(), 'page_theme', true);
- return $page_theme;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement