首页 > 解决方案 > 我的 WordPress 网站的特定页面上的页面加载时间缓慢的问题

问题描述

在我的 WordPress 网站上,我创建了自定义location帖子类型,并使用了一个名为的页面single-locations.php来构建一种模板,以便在显示这些帖子类型时显示。我遇到的问题是在初始页面加载时,每个页面的顶部和底部都会出现一个蓝色条,而顶部的蓝色条会在页面完成加载后一秒钟消失底部没有。这只发生在这些location页面上,而不是网站上的其他任何地方。我检查了我的浏览器这些页面上是否有任何 JavaScript 错误,但没有。想知道是否有人知道可能导致此问题的原因?

这是single-locations.php

<?php
get_header(); 
nectar_page_header($post->ID); 


//full page
$fp_options = nectar_get_full_page_options();
extract($fp_options);

?>
<?php $phone=get_field("phone_number");
$phoneFormat='<a class="phone-span" href="tel:1-'. $phone . '">' . $phone . '</a>';
$phonefootFormat='<a class="phone-footer-link" href="tel:1-'. $phone . '">' . $phone . '</a>';
$phonebodyFormat='<strong>Call Our Customer Service Team ' . '<a class="phone-span" href="tel:1-' . $phone . '">' . $phone . '</a>' . ' or leave a message below</strong>';
$saved_testimonial_raw=remember_testimonial();
$saved_testimonial=str_replace("'", "\'", $saved_testimonial_raw);
?>


<?php 
$image=get_field('background_image');
$city=get_field('city');
$get_started_page_id = get_field( 'get_started_page', 'options' );
$location_finder_page_id = get_field( 'location_finder_page', 'options' );
$location_get_started_button_text = get_field( 'location_get_started_button_text', 'options' );
$location_finder_button_text = get_field( 'location_finder_button_text', 'options' );
$get_started_button = '<a class="nectar-button large see-through-2 " href="' . get_the_permalink($get_started_page_id) . '" data-color-override="false" data-hover-color-override="false" data-hover-text-color-override="#ffffff">
        <span>' . $location_get_started_button_text . '</span>
    </a>';
?>

<div class="location-banner-section" align="center" style="background-image: url(<?php echo $image; ?>); padding-top: 10%; padding-bottom: 10%; background-repeat: no-repeat; background-size: cover;">
    <div>
        <h1 class="location-top"><?php echo $city;?> Pool Cleaning Service</h1> 
    </div>
    <div style= "padding-top: 1%; padding-bottom: 1%;">
        <h2 class="location-top"><?php echo'<a style="color: #ffffff;" href="tel:1-' . $phone . '">' . $phone . '</a>';?></h2> 
    </div>
    <?php echo $get_started_button; ?>
</div>


<div class="container-wrap">

    <div class="main-content">

        <?php 
        //display the price chart
        $include_price_chart = get_field('include_price_chart');

        if($include_price_chart):
        ?>
            <section id="price-chart-wrapper">
                <div class="container">
                    <?php echo sal_full_price_chart(); ?>
                </div>
            </section>

        <?php endif; ?>

        <?php 
            //display the our specials section 
            $include_specials = get_field( 'include_our_specials_section');

            if($include_specials):
                $specials_options = get_field( 'our_specials' );
                $specials_title = ($specials_options['override_specials_title'] ? $specials_options['override_specials_title'] : 'Our Specials');
                $specials_details = $specials_options['our_specials_details'];
        ?>
            <section id="our-specials-wrapper" class="red-background align-center medium-padding medium-spacing">
                <div class="container">
                    <h2 class="light-text"><?php echo $specials_title ?></h2>
                    <div class="description"><?php echo $specials_details ?></div>
                    <?php echo $get_started_button; ?>
                </div>
            </section>
        <?php endif; ?>

        <?php 
        //display the about section
        $include_about_section = get_field('include_about_section_content');

        if($include_about_section):
            $about_section_content = get_field('about_section_content','options');
        ?>
            <section id="about-section-wrapper">
                <div class="container">
                    <?php echo sal_about_section($about_section_content); ?>
                </div>
            </section>

        <?php endif; ?>

        <?php 
        //display the testimonials section
        $include_testimonials_section = get_field('include_testimonials_section');

        if($include_testimonials_section):
        ?>
            <section id="testimonials-section-wrapper" class="large-padding medium-top-spacing">
                <div class="container align-center">
                    <?php echo do_shortcode('[testimonials_widget]'); ?>
                </div>
            </section>

        <?php endif; ?>

        <?php 
            //display the our specials section 
            $include_neighborhood_section = get_field( 'include_neighborhood_section');

            if($include_neighborhood_section):
                $neighborhood_options = get_field( 'neighborhood_content' );
                $neighborhood_title = ($neighborhood_options['override_neighborhood_title'] ? $neighborhood_options['override_neighborhood_title'] : 'We\'re In The Neighborhood');
                $neighborhood_details = $neighborhood_options['neighborhood_details'];
                $neighborhood_photo = $neighborhood_options['neighborhood_photo'];
        ?>
            <section id="our-neighborhood-wrapper" class="lightgray-background medium-padding medium-bottom-spacing flex">
                <div class="container">
                    <div class="row">
                        <div class="col span_6">
                            <h2><?php echo $neighborhood_title ?></h2>
                            <div class="description"><?php echo $neighborhood_details ?></div>
                        </div>
                        <div class="col span_6">
                            <div class="section-photo">
                                <?php echo wp_get_attachment_image($neighborhood_photo['id'], "large"); ?>
                            </div>
                        </div>
                    </div>

                </div>
            </section>
        <?php endif; ?>


        <div class="container">

            <?php 

            //breadcrumbs
            if ( function_exists( 'yoast_breadcrumb' ) && !is_home() && !is_front_page() ){ yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } 

             //buddypress
             global $bp; 
             if($bp && !bp_is_blog_page()) echo '<h1>' . get_the_title() . '</h1>';

             //fullscreen rows
             if($page_full_screen_rows == 'on') echo '<div id="nectar_fullscreen_rows" data-animation="'.$page_full_screen_rows_animation.'" data-row-bg-animation="'.$page_full_screen_rows_bg_img_animation.'" data-animation-speed="'.$page_full_screen_rows_animation_speed.'" data-content-overflow="'.$page_full_screen_rows_content_overflow.'" data-mobile-disable="'.$page_full_screen_rows_mobile_disable.'" data-dot-navigation="'.$page_full_screen_rows_dot_navigation.'" data-footer="'.$page_full_screen_rows_footer.'" data-anchors="'.$page_full_screen_rows_anchors.'">';

                 if(have_posts()) : while(have_posts()) : the_post(); 

                     the_content(); 

                 endwhile; endif; 

            if($page_full_screen_rows == 'on') echo '</div>'; ?>

        </div><!--/container-->

        <?php 
            //display the call-to-action section 
            $include_cta_section = get_field('include_cta_contact_section');

            if($include_cta_section):
                $cta_section = get_field( 'cta_section' );
                $cta_title = ($cta_section['override_section_title'] ? $cta_section['override_section_title'] : 'Call our Residential Pool Customer Service Team');
        ?>
            <section id="contact-cta-wrapper" class="red-background align-center medium-padding medium-top-spacing light-text">
                <div class="container">
                    <h2 class="light-text"><?php echo $cta_title ?></h2>

                    <div>
                        <h2><?php echo'<a href="tel:1-' . $phone . '">' . $phone . '</a>';?></h2> 
                    </div>

                    <a class="nectar-button large see-through-2 " href="<?php echo get_the_permalink($location_finder_page_id) ?>" data-color-override="false" data-hover-color-override="false" data-hover-text-color-override="#ffffff;">
                        <span><?php echo $location_finder_button_text ?></span>
                    </a>
                </div>
            </section>
        <?php endif; ?>

        <div class="widget-container" class="align-center">
            <div class="widget-row" style="padding-top: 5%; padding-bottom: 5%; margin-left: 10%; margin-right: 10%;">
                <?php $review=get_field('yext_review'); echo $review;?>
            </div>  
        </div>

    </div><!--/main-content-->

</div><!--/container-wrap-->
<script>sessionStorage.setItem('lastphone','<?php echo $phoneFormat;?>');</script>
<script>sessionStorage.setItem('lastphonefoot','<?php echo $phonefootFormat;?>');</script>
<script>sessionStorage.setItem('lastphonebody','<?php echo $phonebodyFormat;?>');</script>

<?php $post_id=get_the_ID(); ?>
<script>sessionStorage.setItem('postid','<?php echo $post_id;?>');</script>

<script>sessionStorage.setItem('pricechart','<?php echo do_shortcode("[price_chart]"); ?>');</script>
<script>
sessionStorage.setItem('testimonial','<?php echo $saved_testimonial;?>');
</script>
<?php get_footer(); ?>
?>

主题page.php

<?php 

get_header(); 
nectar_page_header($post->ID); 

//full page
$fp_options = nectar_get_full_page_options();
extract($fp_options);

?>

<div class="container-wrap">

    <div class="<?php if($page_full_screen_rows != 'on') echo 'container'; ?> main-content">

        <div class="row">

            <?php 

            //breadcrumbs
            if ( function_exists( 'yoast_breadcrumb' ) && !is_home() && !is_front_page() ){ yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } 

             //buddypress
             global $bp; 
             if($bp && !bp_is_blog_page()) echo '<h1>' . get_the_title() . '</h1>';

             //fullscreen rows
             if($page_full_screen_rows == 'on') echo '<div id="nectar_fullscreen_rows" data-animation="'.$page_full_screen_rows_animation.'" data-row-bg-animation="'.$page_full_screen_rows_bg_img_animation.'" data-animation-speed="'.$page_full_screen_rows_animation_speed.'" data-content-overflow="'.$page_full_screen_rows_content_overflow.'" data-mobile-disable="'.$page_full_screen_rows_mobile_disable.'" data-dot-navigation="'.$page_full_screen_rows_dot_navigation.'" data-footer="'.$page_full_screen_rows_footer.'" data-anchors="'.$page_full_screen_rows_anchors.'">';

                 if(have_posts()) : while(have_posts()) : the_post(); 

                     the_content(); 

                 endwhile; endif; 

            if($page_full_screen_rows == 'on') echo '</div>'; ?>

        </div><!--/row-->

    </div><!--/container-->

</div><!--/container-wrap-->

<?php get_footer(); ?>

主题single.php

<?php 

get_header(); 
nectar_page_header($post->ID); 

//full page
$fp_options = nectar_get_full_page_options();
extract($fp_options);

?>

<div class="container-wrap">

    <div class="<?php if($page_full_screen_rows != 'on') echo 'container'; ?> main-content">

        <div class="row">

            <?php 

            //breadcrumbs
            if ( function_exists( 'yoast_breadcrumb' ) && !is_home() && !is_front_page() ){ yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } 

             //buddypress
             global $bp; 
             if($bp && !bp_is_blog_page()) echo '<h1>' . get_the_title() . '</h1>';

             //fullscreen rows
             if($page_full_screen_rows == 'on') echo '<div id="nectar_fullscreen_rows" data-animation="'.$page_full_screen_rows_animation.'" data-row-bg-animation="'.$page_full_screen_rows_bg_img_animation.'" data-animation-speed="'.$page_full_screen_rows_animation_speed.'" data-content-overflow="'.$page_full_screen_rows_content_overflow.'" data-mobile-disable="'.$page_full_screen_rows_mobile_disable.'" data-dot-navigation="'.$page_full_screen_rows_dot_navigation.'" data-footer="'.$page_full_screen_rows_footer.'" data-anchors="'.$page_full_screen_rows_anchors.'">';

                 if(have_posts()) : while(have_posts()) : the_post(); 

                     the_content(); 

                 endwhile; endif; 

            if($page_full_screen_rows == 'on') echo '</div>'; ?>

        </div><!--/row-->

    </div><!--/container-->

</div><!--/container-wrap-->

<?php get_footer(); ?>

标签: javascriptphpwordpress

解决方案


推荐阅读