public function render_content() { $llorix_one_all_pages_array = array(); // new array with all pages $llorix_one_all_pages = get_pages(); // get all pages if (!empty($llorix_one_all_pages)) { $llorix_one_all_pages_array[0] = "-- Select --"; foreach ($llorix_one_all_pages as $llorix_one_page) { if (!empty($llorix_one_page->ID) && !empty($llorix_one_page->post_title)) { $llorix_one_all_pages_array[$llorix_one_page->ID] = $llorix_one_page->post_title; } } } if (!empty($llorix_one_all_pages_array)) { // change the frontpage control with the new array echo '<label>'; echo '<span class="customize-control-title">' . esc_html($this->label) . '</span>'; echo '<select data-customize-setting-link="page_on_front" name="_customize-dropdown-pages-page_on_front" id="_customize-dropdown-pages-page_on_front">'; foreach ($llorix_one_all_pages_array as $llorix_one_all_pages_array_k => $llorix_one_all_pages_array_v) { $llorix_one_page_template = get_page_template_slug($llorix_one_all_pages_array_k); if (!empty($llorix_one_page_template)) { echo '<option value="' . $llorix_one_all_pages_array_k . '" template="' . $llorix_one_page_template . '">' . $llorix_one_all_pages_array_v . '</option>'; } else { echo '<option value="' . $llorix_one_all_pages_array_k . '" template="default">' . $llorix_one_all_pages_array_v . '</option>'; } } echo '</select>'; echo '</label>'; } }
public function display($post) { if (!empty($this->settings['page_template'])) { //echo $this->settings['page_template']; $page_template = get_page_template_slug(get_queried_object_id()); if ($page_template != $this->settings['page_template']) { return false; } } $this->postID = $post->ID; wp_nonce_field($this->settings['id'], TF . '_' . $this->settings['id'] . '_nonce'); if (!empty($this->settings['desc'])) { ?> <p class='description'><?php echo $this->settings['desc']; ?> </p><?php } ?> <table class="form-table tf-form-table"> <tbody> <?php foreach ($this->options as $option) { $option->display(); } ?> </tbody> </table> <?php }
/** * Remove "hentry" from page post_class if the page template is "Optimize for MP Stacks" * * @since 1.0 * @return void */ function mp_stacks_remove_hentry_from_stack_page_templates($classes) { global $post; $class_name_counter = 0; //Loop through each class name foreach ($classes as $class_name) { $page_template_slug = get_page_template_slug($post->ID); //If one of the class names is hentry if ($class_name == 'hentry') { //If we are using the mp-stacks-page-template if (get_page_template_slug($post->ID) == 'mp-stacks-page-template.php') { //Remove hentry from the classes array $classes[$class_name_counter] = ''; } else { if (empty($page_template_slug)) { //Check the title of the default page template - This filter: https://core.trac.wordpress.org/ticket/27178 $default_page_template_title = apply_filters('default_page_template_title', __('Default Template')); //If the default page template's title includes the word "Stack" if (strpos($default_page_template_title, 'Stack') !== false) { //Remove hentry from the classes array $classes[$class_name_counter] = ''; } } } } $class_name_counter = $class_name_counter + 1; } return $classes; }
function menu_endpoint($data) { $args = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 'update_post_term_cache' => false); $menu = wp_get_nav_menu_items($data['id'], $args); $fallback_menu = wp_get_nav_menu_items('2', $args); $menu = json_decode(json_encode($menu), true); $fallback_menu = json_decode(json_encode($fallback_menu), true); if ($menu != false) { $menu = $menu; } else { $menu = $fallback_menu; } for ($i = 0; $i < sizeof($menu); $i++) { unset($menu[$i]['post_password']); unset($menu[$i]['post_name']); unset($menu[$i]['to_ping']); unset($menu[$i]['pinged']); unset($menu[$i]['post_modified']); unset($menu[$i]['post_modified_gmt']); unset($menu[$i]['post_content_filtered']); unset($menu[$i]['post_parent']); unset($menu[$i]['post_mime_type']); unset($menu[$i]['comment_count']); unset($menu[$i]['filter']); unset($menu[$i]['object']); unset($menu[$i]['type']); unset($menu[$i]['post_date']); unset($menu[$i]['post_date_gmt']); $menu[$i]['template'] = split('.php', get_page_template_slug($menu[$i]['object_id']))[0]; } //if the id would return nothing - return the default menu return $menu; }
function kt_metabox_show_on_kt_template($display, $meta_box) { if ('kt-template' !== $meta_box['show_on']['key']) { return $display; } // Get the current ID if (isset($_GET['post'])) { $post_id = $_GET['post']; } elseif (isset($_POST['post_ID'])) { $post_id = $_POST['post_ID']; } if (!isset($post_id)) { return false; } $template_name = get_page_template_slug($post_id); $template_name = substr($template_name, 0, -4); // If value isn't an array, turn it into one $meta_box['show_on']['value'] = !is_array($meta_box['show_on']['value']) ? array($meta_box['show_on']['value']) : $meta_box['show_on']['value']; // See if there's a match if (in_array($template_name, $meta_box['show_on']['value'])) { return false; } else { return true; } }
public function get_hidden_layouts($field) { global $wpdb, $post; if (!isset($field["parent_layout"])) { return; } if (is_object($post) && isset($post->ID)) { $post_id = $post->ID; } else { return; } $template = get_page_template_slug($post_id); $content = $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->posts} WHERE post_name = %s", $field["parent"])); $content = unserialize($content); $hides = array(); if (is_array($content) && isset($content["layouts"])) { foreach ($content["layouts"] as $layout) { if (!isset($layout["visibility"])) { continue; } $visibility = array_filter(explode(" ", str_replace(",", " ", $layout["visibility"]))); if (in_array($template, $visibility)) { $hides[$layout["name"]] = $layout["visibility"]; } } } foreach ($hides as $key => $hide) { $this->css[] = "div.acf-fc-popup a[data-layout='" . $key . "'] { display: none; }\n"; } }
public function conditional_scripts() { global $PhoenixData, $template; $what_template = get_page_template_slug(); if ($what_template == 'template-portfolio.php' || basename($template) == 'single-' . THEME_SLUG . '_portfolio.php') { $cubeportfolio = array('inlineError' => __("Error! Please refresh the page!", 'grandway'), 'moreLoading' => __("Loading...", 'grandway'), 'moreNoMore' => __("No More Works", 'grandway')); $port_layout = isset($PhoenixData['port_layout']) ? $PhoenixData['port_layout'] : '2-cols'; switch ($port_layout) { case '2-cols': $cube_js = 'portfolio-2'; break; case '3-cols': $cube_js = 'portfolio-3'; break; case '4-cols': $cube_js = 'portfolio-4'; break; case 'full': $cube_js = 'portfolio-fullwidth'; break; default: $cube_js = 'portfolio-2'; break; } wp_register_script(THEME_SLUG . '-portfolio', THEME_URI . '/assets/js/' . $cube_js . '.js', array('jquery'), '1.0.0', true); wp_enqueue_script(THEME_SLUG . '-portfolio'); wp_localize_script(THEME_SLUG . '-jquery.cubeportfolio', 'portSetts', $cubeportfolio); } if (is_singular(THEME_SLUG . '_portfolio')) { wp_dequeue_script(THEME_SLUG . '-portfolio'); wp_enqueue_script(THEME_SLUG . '-portfolio-single', THEME_URI . '/assets/js/portfolio-3.js', array('jquery'), '1.0.0', true); } }
function wptgbs_link_to_id_filter($atts, $item, $args) { if (get_page_template_slug() == 'home.php') { // $atts['href'] = '#'.get_post_type($item->object_id).'-'.$item->object_id; $atts['href'] = '#post-' . $item->object_id; } return $atts; }
/** * Get current template * * @return string */ function get_current_template() { // Get page id for all pages and detail pages global $post; // $page_id = (isset($post->detail_id)) ? $post->detail_id: get_queried_object_id(); $page_id = isset($post->ID) ? $post->ID : get_queried_object_id(); return basename(get_page_template_slug($page_id), '.php'); }
/** * Is the current page a Page Builder Page ? * * @since 1.3.0 * @return string html menu */ function quest_is_pb_template() { global $post; if ($post && !is_search() && get_page_template_slug($post->ID) === 'page-builder.php') { return true; } return false; }
function rs_theme_show_if_full_width($cmb) { // Show this metabox if it's full width if ('page-templates/template-fullwidth.php' == get_page_template_slug($cmb->object_id)) { return true; } return false; }
public function addMetaBox() { $templates = get_page_templates(); $template = get_page_template_slug(); if ($this->pageTemplate == 'any' || $templates[$this->pageTemplate] == $template) { add_meta_box($this->id, $this->title, [$this->metaTemplate, 'getHtml'], $this->type, $this->context, $this->priority); } }
/** * add body tags to mce editor based on current template */ function teaberry_add_mce_body_tags($classes) { global $post; $template = get_page_template_slug($post->ID); if ($template == 'page-templates/full-width.php') { $classes['body_class'] = 'full-width'; } return $classes; }
private function setCurrentPostInformation() { //Parse our WordPress template formatting to get another potential match for content. $this->currentPostInfo = array('id' => get_the_ID(), 'title' => get_the_title(), 'slug' => basename(get_permalink()), 'templateType' => ''); if (is_page_template()) { $rawSlug = preg_match('/(?<=\\/).*?(?=-)/', get_page_template_slug(), $matchedSlug); $this->currentPostInfo['templateType'] = $matchedSlug[0] . "-section-sidebar"; } }
/** * Filter that allow to change the sizes on pages that uses custom * page templates. * * @since 1.1.0 * * @param array $sizes The images sizes. * @param int $id The id of the post, page or custom post type. * @return return the array with the new sizes. */ public function filter_by_template_page($sizes, $id = 0) { $template = get_page_template_slug($id); if (empty($template)) { return $sizes; } $template_name = Formatter::to_filter_format($template); return apply_filters(Formatter::katana_filter($template_name), $sizes); }
/** * @file * Copyright (C) 2014 TopCoder Inc., All Rights Reserved. * @author TCSASSEMBLER, ecnu_haozi * @version 1.1 * * Enqueue scripts and stylesheets * * CDN will also be used for jquery. We will have a local fallback * The theme option jsCssUseCDN will be used to say if local files will be on the cdn. * Grunt script is what pushes the script. * Theme option jsCssUseMin will be used to only enqueue the min version. * Grunt will create a style.css and script.js file that will contain all of the local code * * Changed in 1.1 * Add angular-animation.js. */ function tcs_responsive_scripts() { // register scripts that are used everywhere $assets = array('jquery' => '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', 'jquery_ui' => '//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js', 'respond' => '/js/vendor/respond.min.js', 'modernizr' => '/js/vendor/modernizr.js', 'html5shiv' => '/js/vendor/html5shiv.js', 'auth0' => '//cdn.auth0.com/w2/auth0-1.6.4.js'); tsc_register_master($assets); $jsCssUseMin = TC_USE_MIN; $template_map = tsc_get_asset_map(); $queried_object_id = get_queried_object_id(); if ($queried_object_id !== 0) { $page_template = get_page_template_slug($queried_object_id); } $ver = TC_CDN_VER == 1 ? TC_CDN_VER : '1'; $jsCssUseCDN = TC_USE_CDN; if (isset($page_template) && isset($template_map[$page_template])) { $asset_map = $template_map[$page_template]; } else { $asset_map = $template_map['default']; } if ($jsCssUseMin && $jsCssUseCDN) { // version number is in url when using cdn wp_register_script($asset_map['name'], tsc_build_asset_path($asset_map['name'], 'js', true, true), array('jquery', 'jquery_ui', 'auth0'), null, true); wp_register_style($asset_map['name'], tsc_build_asset_path($asset_map['name'], 'css', true, true)); wp_enqueue_script($asset_map['name']); wp_enqueue_style($asset_map['name']); } elseif ($jsCssUseMin) { // version number is in url when using cdn wp_register_script($asset_map['name'], tsc_build_asset_path($asset_map['name'], 'js', true), array('jquery', 'jquery_ui', 'auth0'), $ver, true); wp_register_style($asset_map['name'], tsc_build_asset_path($asset_map['name'], 'css', true), array(), $ver); wp_enqueue_script($asset_map['name']); wp_enqueue_style($asset_map['name']); } else { $i = 0; foreach ($asset_map['js'] as $js_script) { if ($i == 0) { wp_register_script("custom-{$i}", tsc_build_asset_path($js_script, 'js'), array("jquery", "auth0"), $ver, true); } else { $j = $i - 1; wp_register_script("custom-{$i}", tsc_build_asset_path($js_script, 'js'), array("custom-{$j}"), $ver, true); } wp_enqueue_script("custom-{$i}"); $i++; } $i = 0; foreach ($asset_map['css'] as $css_script) { if ($i == 0) { wp_enqueue_style("custom-{$i}", tsc_build_asset_path($css_script, 'css'), array(), $ver); } else { $j = $i - 1; wp_enqueue_style("custom-{$i}", tsc_build_asset_path($css_script, 'css'), array("custom-{$j}"), $ver); } $i++; } } }
/** * Gets the template file from the id. If the template is not in use by the * current theme then 'default' is returned. This does not handle page * specific php files. * * @param int id The id of the page template to return. If no id is specified * then the id of the current page is used. * * @return string The template name if it is in use, default otherwise */ private static function getPageTemplate($id = null) { $template = get_page_template_slug($id); if (is_string($template) && $template != '') { $templates = wp_get_theme()->get_page_templates(); if (array_key_exists($template, $templates)) { return $template; } } return 'default'; }
/** * Determine if a post should display in a single column or not. * * @since 1.1.3. * * @param int $post_id The post ID. * @return bool True if post should display in single column. */ function oxford_is_single_column($post_id) { $post_id = absint($post_id); $is = false; $char_count = oxford_get_post_char_count($post_id); $threshold = oxford_get_post_char_threshold(); if (0 !== $post_id && ($char_count < $threshold && (is_single() || is_page() && 'two-column-page.php' === get_page_template_slug()) || is_single() && true === oxford_get_post_meta('settings', $post_id, 'post-single-column'))) { $is = true; } return apply_filters('oxford_is_single_column', $is, $post_id); }
function trunck_modular_css() { // Enqueue the main Stylesheet. if (ENVIRONMENT == "development") { wp_enqueue_style('trunck-main-stylesheet', get_stylesheet_directory_uri() . '/css/global.css', array(), $version, "screen"); error_log("page slug: " . get_page_template_slug()); } else { wp_enqueue_style('trunck-main-stylesheet', get_stylesheet_directory_uri() . '/css/global.min.css', array(), $version, "screen"); } wp_enqueue_style('trunck-print-stylesheet', get_stylesheet_directory_uri() . '/css/print.min.css', array(), $version, "print"); wp_enqueue_style('trunck-theme-stylesheet', get_stylesheet_directory_uri() . '/style.css', array(), $version, "screen"); }
/** * Returns the type for the post, the term template applies to what type of * post is or what type of template is using. * * @param Int|\WP_Post $post The post * @return string */ public static function get($post) { $post = is_a($post, 'WP_Post') ? $post : get_post($post); $type = $post->post_type; if ('page' === $type) { $template_slug = get_page_template_slug($post->ID); if (!empty($template_slug)) { $type .= '-' . wp_basename($template_slug, '.php'); } } return $type; }
function my_short_page_template_body_classes($classes) { if (is_page()) { $template = get_page_template_slug(); // returns an empty string if it's loading the default template (page.php) if ($template === '') { $classes[] = 'default-page'; } else { $classes[] = sanitize_html_class(str_replace('.php', '', $template)); } } return $classes; }
public function test_create_item_with_template() { wp_set_current_user($this->editor_id); $this->setup_test_template(); $request = new WP_REST_Request('POST', '/wp/v2/pages'); $params = $this->set_post_data(array('template' => 'page-my-test-template.php')); $request->set_body_params($params); $response = $this->server->dispatch($request); $data = $response->get_data(); $new_post = get_post($data['id']); $this->assertEquals('page-my-test-template.php', $data['template']); $this->assertEquals('page-my-test-template.php', get_page_template_slug($new_post->ID)); }
/** * Determine whether the layout is forced on the current page. * * @since 1.0.0 * @access public * @param int $post_id The post ID for the post to be checked. * @return bool true if the current layout is forced, false otherwise */ function alpha_is_page_layout_forced($post_id) { if (get_option('page_on_front') === $post_id) { return true; } $forced_templates = array(); foreach ($forced_templates as $template) { if (get_page_template_slug($post_id)) { return true; } } return false; }
/** * Retrieves the controller for the post type * @since 0.7.0 * @param string|int|object $post id, slug, or WP_Post object * @param array $options * @return Controller */ public static function get_controller($key = null, $options = array()) { if (is_null($key)) { global $post; $key = $post; if (empty($key)) { return new WP_Error('no_global_post', 'Global post is null', $key); } } // Check for cached object and set $post to the WP_Post otherwise if (is_numeric($key)) { $cached_post = wp_cache_get($key, 'postcontroller'); if (false !== $cached_post) { return $cached_post; } $_post = get_post(intval($key)); if (!$_post) { return new WP_Error('post_id_not_found', 'No post was found for the provided ID', $key); } } elseif (is_string($key)) { $post_id = wp_cache_get($key, 'postcontroller_slug'); if (false !== $post_id) { return wp_cache_get($post_id, 'postcontroller'); } $posts = get_posts(array('name' => $key, 'post_type' => 'any', 'post_status' => array('publish', 'private'), 'numberposts' => 1)); if (empty($posts)) { return new WP_Error('post_slug_not_found', 'No post was found for the provided slug', $key); } $_post = $posts[0]; } elseif (is_object($key)) { $_post = wp_cache_get($key->ID, 'postcontroller'); if (false !== $_post) { return $_post; } $_post = $key; } else { return new WP_Error('invalid_key_type', 'Key provied is unsupported type', $key); } // Construct, cache, and return post if ($_post->post_type === 'page') { $template = str_replace('.php', '', get_page_template_slug($_post)); $controller = $template && isset(self::$page_templates[$template]) ? new self::$page_templates[$template]($_post) : new Page($_post); } elseif ($_post->post_type === 'attachment' && wp_attachment_is_image($_post->ID)) { $controller = new self::$post_types['image']($_post); } else { $controller = isset(self::$post_types[$_post->post_type]) ? new self::$post_types[$_post->post_type]($_post) : new self($_post); } wp_cache_set($controller->slug, $controller->id, 'postcontroller_slug', MINUTE_IN_SECONDS * 10); wp_cache_set($controller->id, $controller, 'postcontroller', MINUTE_IN_SECONDS * 10); return $controller; }
/** * Get current layout */ function responsive_mobile_get_layout() { if (is_404()) { return 'default'; } $layout = ''; $responsive_mobile_options = responsive_mobile_get_options(); $valid_layouts = responsive_mobile_valid_layouts(); /* For singular pages, get post meta */ if (is_singular()) { global $post; } /* Static pages */ if (is_page()) { $page_template = get_page_template_slug($post->ID); /* If custom page template is default, use page template first */ if (in_array($page_template, array('page-templates/blog.php', 'page-templates/blog-excerpt.php'))) { if ('default' == $responsive_mobile_options['blog_posts_index_layout_default']) { $layout = basename($page_template, '.php'); } else { $layout = $responsive_mobile_options['blog_posts_index_layout_default']; } } else { // If page is set to default then display default layout if ('' == $page_template) { $layout = $responsive_mobile_options['static_page_layout_default']; } else { $layout = basename($page_template, '.php'); } } } elseif (is_single()) { $layout_meta_value = false != get_post_meta($post->ID, '_responsive_mobile_layout', true) ? get_post_meta($post->ID, '_responsive_mobile_layout', true) : 'default'; $layout_meta = array_key_exists($layout_meta_value, $valid_layouts) ? $layout_meta_value : 'default'; /* If post custom meta is set, use it */ if ('default' != $layout_meta) { $layout = $layout_meta; } else { $layout = $responsive_mobile_options['single_post_layout_default']; } } else { /* Posts index */ if (is_home() || is_archive() || is_search()) { $layout = $responsive_mobile_options['blog_posts_index_layout_default']; } else { $layout = 'default'; } } $layout = apply_filters('responsive_mobile_get_layout', $layout); return esc_attr($layout); }
/** * Checks for modular template and hides editor on loading * to avoid display of unstyled content (until jQuery scripts load) */ function qi_modular_hide_editor() { $post_id = get_the_id(); // Return early if nof editing a page if (get_post_type($post_id) !== 'page') { return false; } // Return early if not a modular one if (get_page_template_slug($post_id) !== 'template-modular.php') { return false; } // Hide editor early echo '<style>#postdivrich { display: none; } #modular-qi-template-metabox { display: block; }</style>'; }
public static function current() { global $post; if ($post) { $slug = get_page_template_slug($post->ID); if (static::has($slug)) { return static::get($slug); } if (is_single() && static::has('single.php')) { return static::get('single.php'); } } return null; }
/** * Loads a template based off the post type and/or the post format. * @since 0.1.0 */ function tamatebako_get_template($dir = 'content') { /* Filter Dir */ $dir = apply_filters('tamatebako_get_template_dir', $dir); /* Set up an empty array and get the post type. */ $templates = array(); $post_type = get_post_type(); /* Singular suffix. */ $singular = ''; if (is_singular($post_type)) { $singular = '-singular'; } /* Assume the theme developer is creating an attachment template. */ if (is_attachment() && 'attachment' === $post_type) { remove_filter('the_content', 'prepend_attachment'); $mime_type = get_post_mime_type(); list($type, $subtype) = false !== strpos($mime_type, '/') ? explode('/', $mime_type) : array($mime_type, ''); $templates[] = "{$dir}/attachment-{$type}.php"; } /* If the post type supports 'post-formats', get the template based on the format. */ if (current_theme_supports('post-formats') && post_type_supports($post_type, 'post-formats')) { /* Get theme post format support. */ $theme_support_format = get_theme_support('post-formats'); /* Get the post format. */ $format = get_post_format() ? get_post_format() : 'standard'; /* Only if theme support specific format */ if (is_array($theme_support_format[0]) && in_array($format, $theme_support_format[0])) { /* Template based off post type and post format. */ $templates[] = "{$dir}/{$post_type}-format-{$format}{$singular}.php"; $templates[] = "{$dir}/{$post_type}-format-{$format}.php"; } } /* Page Template (only for singular) */ if (is_page() && get_page_template_slug()) { $page_template_base = str_replace('.php', '', basename(get_page_template_slug())); $templates[] = "{$dir}/page-singular-{$page_template_base}.php"; } /* Template based off the post type. */ $templates[] = "{$dir}/{$post_type}{$singular}.php"; $templates[] = "{$dir}/{$post_type}.php"; /* Fallback 'content.php' template. */ $templates[] = "{$dir}/content{$singular}.php"; $templates[] = "{$dir}/content.php"; /* Remove Duplicates. */ $templates = array_unique($templates); /* Apply filters and return the found content template. */ include locate_template($templates, false, false); }
/** * get_children * */ protected function get_pages() { if (empty($this->pages)) { $args = array('post_parent' => $this->get_post()->ID, 'post_type' => 'page', 'numberposts' => -1, 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC'); $this->pages = array($this->get_post()); $children = get_children($args); foreach ($children as &$child) { $page = new \TimberPost($child); $template = get_page_template_slug($page->ID); $template = preg_replace(array('/.*\\//', '/\\.php/i'), array('', '.twig'), $template); $page->template = $template; $this->pages[] = $page; } } return $this->pages; }
protected function GetPostTemplate($post) { $id = $post->ID; $template = get_page_template_slug($id); $pagename = $post->post_name; $templates = array(); if ($template && 0 === validate_file($template)) { $templates[] = $template; } if ($pagename) { $templates[] = "page-{$pagename}.php"; } if ($id) { $templates[] = "page-{$id}.php"; } $templates[] = 'page.php'; return get_query_template('page', $templates); }