get_page_template_slug example


function wp_get_post_content_block_attributes() {
    global $post_ID;

    $is_block_theme = wp_is_block_theme();

    if ( ! $is_block_theme || ! $post_ID ) {
        return array();
    }

    $template_slug = get_page_template_slug( $post_ID );

    if ( ! $template_slug ) {
        $post_slug      = 'singular';
        $page_slug      = 'singular';
        $template_types = get_block_templates();

        foreach ( $template_types as $template_type ) {
            if ( 'page' === $template_type->slug ) {
                $page_slug = 'page';
            }
            if ( 'single' === $template_type->slug ) {
                
$classes[] = 'error404';
    }

    if ( is_singular() ) {
        $post_id   = $wp_query->get_queried_object_id();
        $post      = $wp_query->get_queried_object();
        $post_type = $post->post_type;

        if ( is_page_template() ) {
            $classes[] = "{$post_type}-template";

            $template_slug  = get_page_template_slug( $post_id );
            $template_parts = explode( '/', $template_slug );

            foreach ( $template_parts as $part ) {
                $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
            }
            $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
        } else {
            $classes[] = "{$post_type}-template-default";
        }

        if ( is_single() ) {
            

function get_page_template() {
    $id       = get_queried_object_id();
    $template = get_page_template_slug();
    $pagename = get_query_var( 'pagename' );

    if ( ! $pagename && $id ) {
        /* * If a static page is set as the front page, $pagename will not be set. * Retrieve it from the queried object. */
        $post = get_queried_object();
        if ( $post ) {
            $pagename = $post->post_name;
        }
    }

    public function check_template( $template$request ) {

        if ( ! $template ) {
            return true;
        }

        if ( $request['id'] ) {
            $post             = get_post( $request['id'] );
            $current_template = get_page_template_slug( $request['id'] );
        } else {
            $post             = null;
            $current_template = '';
        }

        // Always allow for updating a post to the same template, even if that template is no longer supported.         if ( $template === $current_template ) {
            return true;
        }

        // If this is a create request, get_post() will return null and wp theme will fallback to the passed post type.
$body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );

                if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
                    $post_format = get_post_format( $post );
                    if ( $post_format && ! is_wp_error( $post_format ) ) {
                        $body_class .= ' post-format-' . sanitize_html_class( $post_format );
                    } else {
                        $body_class .= ' post-format-standard';
                    }
                }

                $page_template = get_page_template_slug( $post );

                if ( false !== $page_template ) {
                    $page_template = empty( $page_template ) ? 'default' : str_replace( '.', '-', basename( $page_template, '.php' ) );
                    $body_class   .= ' page-template-' . sanitize_html_class( $page_template );
                }
            }

            $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );

            if ( ! empty( $set['tinymce']['body_class'] ) ) {
                $body_class .= ' ' . $set['tinymce']['body_class'];
                
// Pull the categories info together.         $categories = array();
        if ( is_object_in_taxonomy( 'page', 'category' ) ) {
            foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) {
                $categories[] = get_cat_name( $cat_id );
            }
        }

        // Get the author info.         $author = get_userdata( $page->post_author );

        $page_template = get_page_template_slug( $page->ID );
        if ( empty( $page_template ) ) {
            $page_template = 'default';
        }

        $_page = array(
            'dateCreated'            => $page_date,
            'userid'                 => $page->post_author,
            'page_id'                => $page->ID,
            'page_status'            => $page->post_status,
            'description'            => $full_page['main'],
            'title'                  => $page->post_title,
            
Home | Imprint | This part of the site doesn't use cookies.