/** * 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; }
/** * Script for layout thumbnail * use jQuery .click() and not .change() because it's too late(?) * @since 3.0.0 */ function tamatebako_post_layouts_thumb_script() { global $post_type; if (in_array($post_type, tamatebako_layouts_post_types())) { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { $( ".theme-layout-input" ).click( function(){ /* if it's already selected, remove it and select default. */ if( $( this ).parent( '.theme-layout-label' ).hasClass( 'layout-selected' ) ){ $( '.layout-default .theme-layout-input' ).attr('checked', 'checked'); $( this ).parent( '.theme-layout-label' ).removeClass( 'layout-selected' ); } /* not yet selected, select it! */ else{ $( this ).parent( '.theme-layout-label' ).siblings( '.theme-layout-label' ).removeClass( 'layout-selected' ); $( this ).parent( '.theme-layout-label' ).addClass( 'layout-selected' ); } /* if a layout is selected, add wrapper class */ if ( $( ".layout-selected" ).length ) { $( '.post-layout' ).addClass( 'post-layout-selected' ); } else{ $( '.post-layout' ).removeClass( 'post-layout-selected' ); } }); }); </script> <?php } }