简体   繁体   中英

WordPress Avada Theme Fatal Error: Call to a member function add_style() on a non-objet in ~/themes/Avada/page.php on line 2

I do not know whether it is a new update of Avada theme that broke the program, but the site was working just fine until I was notified by the user that the page is getting an error message. So here is the code of page.php

<?php get_header(); ?>
    <div id="content" <?php Avada()->layout->add_style( 'content_style' ); ?>>
        <?php
        while( have_posts() ): the_post();
        ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <?php echo avada_render_rich_snippets_for_pages(); ?>
            <?php if( ! post_password_required($post->ID) ): // 1 ?>
            <?php if(!Avada()->settings->get( 'featured_images_pages' ) ): // 2 ?>
            <?php
            if( avada_number_of_featured_images() > 0 || get_post_meta( $post->ID, 'pyre_video', true ) ): // 3
            ?>
            <div class="fusion-flexslider flexslider post-slideshow">
                <ul class="slides">
                    <?php if(get_post_meta($post->ID, 'pyre_video', true)): ?>
                    <li>
                        <div class="full-video">
                            <?php echo get_post_meta($post->ID, 'pyre_video', true); ?>
                        </div>
                    </li>
                    <?php endif; ?>
                    <?php if( has_post_thumbnail() && get_post_meta( $post->ID, 'pyre_show_first_featured_image', true ) != 'yes' ): ?>
                    <?php $attachment_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?>
                    <?php $full_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?>
                    <?php $attachment_data = wp_get_attachment_metadata(get_post_thumbnail_id()); ?>
                    <li>
                        <a href="<?php echo $full_image[0]; ?>" rel="prettyPhoto[gallery<?php the_ID(); ?>]" title="<?php echo get_post_field('post_excerpt', get_post_thumbnail_id()); ?>" data-title="<?php echo get_post_field('post_title', get_post_thumbnail_id()); ?>" data-caption="<?php echo get_post_field('post_excerpt', get_post_thumbnail_id()); ?>"><img src="<?php echo $attachment_image[0]; ?>" alt="<?php echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true); ?>" /></a>
                    </li>
                    <?php endif; ?>
                    <?php
                    $i = 2;
                    while($i <= Avada()->settings->get( 'posts_slideshow_number' )):
                    $attachment_new_id = kd_mfi_get_featured_image_id('featured-image-'.$i, 'page');
                    if($attachment_new_id):
                    ?>
                    <?php $attachment_image = wp_get_attachment_image_src($attachment_new_id, 'full'); ?>
                    <?php $full_image = wp_get_attachment_image_src($attachment_new_id, 'full'); ?>
                    <?php $attachment_data = wp_get_attachment_metadata($attachment_new_id); ?>
                    <li>
                        <a href="<?php echo $full_image[0]; ?>" rel="prettyPhoto[gallery<?php the_ID(); ?>]" title="<?php echo get_post_field('post_excerpt', $attachment_new_id); ?>" data-title="<?php echo get_post_field( 'post_title', $attachment_new_id ); ?>" data-caption="<?php echo get_post_field('post_excerpt', $attachment_new_id ); ?>"><img src="<?php echo $attachment_image[0]; ?>" alt="<?php echo get_post_meta($attachment_new_id, '_wp_attachment_image_alt', true); ?>" /></a>
                    </li>
                    <?php endif; $i++; endwhile; ?>
                </ul>
            </div>
            <?php endif; // 3 ?>
            <?php endif; // 2 ?>
            <?php endif; // 1 password check ?>
            <div class="post-content">
                <?php the_content(); ?>
                <?php avada_link_pages(); ?>
            </div>
            <?php if( ! post_password_required($post->ID) ): ?>
            <?php if(class_exists('WooCommerce')): ?>
            <?php
            $woo_thanks_page_id = get_option('woocommerce_thanks_page_id');
            if( ! get_option('woocommerce_thanks_page_id') ) {
                $is_woo_thanks_page = false;
            } else {
                $is_woo_thanks_page = is_page( get_option( 'woocommerce_thanks_page_id' ) );
            }
            ?>
            <?php if(Avada()->settings->get( 'comments_pages' ) && !is_cart() && !is_checkout() && !is_account_page() && ! $is_woo_thanks_page ): ?>
                <?php
                wp_reset_query();
                comments_template();
                ?>
            <?php endif; ?>
            <?php else: ?>
            <?php if(Avada()->settings->get( 'comments_pages' )): ?>
                <?php
                wp_reset_query();
                comments_template();
                ?>
            <?php endif; ?>
            <?php endif; ?>
            <?php endif; // password check ?>
        </div>
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
    </div>
    <?php do_action( 'fusion_after_content' ); ?>
<?php get_footer();

// Omit closing PHP tag to avoid "Headers already sent" issues.

Line 2 is:

<div id="content" <?php Avada()->layout->add_style( 'content_style' ); ?>>

I think I understand from similar posts and questions that the solution would be to register layout , which appears as a non-object right now. But how do I go about registering it?

It turns out that even WordPress had noticed some missing files in the theme. I am not really sure what stole them from the system that was working just fine until they went missing.

The rather simplistic solution to this issue turned out to be a fresh install of the theme. I wiped out the existing files of the Avada theme and downloaded new ones for a fresh installation. The Avada theme authors narrowed down the issue a missing class-avada.php in the /wp-content/themes/avada/includes directory. To solve the issue, they too suggested a fresh install of all the files.

According to WordPress, the stylesheet was missing. 请查看所附图片:WordPress错误通知屏幕截图

Warning : If you had customized the theme with custom code, please remember to save your custom files before uninstalling and erasing the entire theme folder.

Note : Considering that this type of issue needs a specific solution to the specific problem being encountered and considering that the problem I faced is a generic issue in PHP with non-generic solution, I thought it better to post as answer what actually solved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM