未定义变量&SMOF_DATA问题

时间:2017-01-30 作者:Paweł Skaba

我正在帮助我的同事处理他的当前页面,但我遇到了一个错误:

未定义变量:对齐

它引用了以下代码:

if( ! function_exists( \'avada_page_title_bar\' ) ) {
    /**
     * Render the HTML markup of the page title bar
     * @param  string $title                Main title; page/post title or custom title set by user
     * @param  string $subtitle             Subtitle as custom user setting
     * @param  string $secondary_content    HTML markup of the secondary content; breadcrumbs or search field
     *
     * @return void                         Content is directly echoed
     **/
    function avada_page_title_bar( $title, $subtitle, $secondary_content ) {
        global $smof_data;
        $post_id = get_queried_object_id();

        // Check for the secondary content
        $content_type = \'none\';
        if ( strpos( $secondary_content, \'searchform\' ) !== FALSE ) {
            $content_type = \'search\';
        } elseif ( $secondary_content != \'\' ) {
            $content_type = \'breadcrumbs\';
        }

        // Check the position of page title
        if ( metadata_exists( \'post\', $post_id, \'pyre_page_title_text_alignment\' ) && 
             get_post_meta( get_queried_object_id(), \'pyre_page_title_text_alignment\', TRUE ) != \'default\' 
        ) {
            $alignment = get_post_meta( $post_id, \'pyre_page_title_text_alignment\', TRUE );
        } elseif ( $smof_data[\'page_title_alignment\'] ) {
            $alignment = $smof_data[\'page_title_alignment\'];
        }

        // Render the page title bar
        echo sprintf( \'<div class="fusion-page-title-bar fusion-page-title-bar-%s fusion-page-title-bar-%s">\', $content_type, $alignment );
            echo \'<div class="fusion-page-title-row">\';
                echo \'<div class="fusion-page-title-wrapper">\';
                    echo \'<div class="fusion-page-title-captions">\';
                        if( $title ) {
                            // Add entry-title for rich snippets
                            $entry_title_class = \'\';
                            if ( ! $smof_data[\'disable_date_rich_snippet_pages\'] ) { 
                                $entry_title_class = \' class="entry-title"\';
                            }                   
                            echo sprintf( \'<h1%s>%s</h1>\', $entry_title_class, $title );

                            if ( $subtitle ) {
                                echo sprintf( \'<h3>%s</h3>\', $subtitle );
                            }

                            if ( get_field( "data_i_miejsce_koncertu" ) && is_single() ) {
                                echo ( \'<h3>\' . get_field( "data_i_miejsce_koncertu" ) . \'</h3>\' );
                            }
                        }

                        // Render secondary content on center layout
                        if ( $alignment == \'center\') {
                            if ( fusion_get_option( \'page_title_bar_bs\', \'page_title_breadcrumbs_search_bar\', $post_id ) != \'none\' ) {
                                echo \'<div class="fusion-page-title-secondary">\';
                                    echo $secondary_content;
                                echo \'</div>\';
                            }
                        }

                    echo \'</div>\';

                    // Render secondary content on left/right layout
                    if ( $alignment != \'center\' ) {
                        if ( fusion_get_option( \'page_title_bar_bs\', \'page_title_breadcrumbs_search_bar\', $post_id ) != \'none\' ) {
                            echo \'<div class="fusion-page-title-secondary">\';
                                echo $secondary_content;
                            echo \'</div>\';
                        }
                    }

                echo \'</div>\';
            echo \'</div>\';
        echo \'</div>\';
    }
}
错误链接到以下行:

echo sprintf( \'<div class="fusion-page-title-bar fusion-page-title-bar-%s fusion-page-title-bar-%s">\', $content_type, $alignment );
以及

if ( $alignment == \'center\') {
以及

            if ( $alignment != \'center\' ) {
为什么会这样$路线在开头定义。。

谢谢

1 个回复
最合适的回答,由SO网友:JHoffmann 整理而成

变量$alignment 仅通过以下行有条件地设置:

if ( metadata_exists( \'post\', $post_id, \'pyre_page_title_text_alignment\' ) && 
             get_post_meta( get_queried_object_id(), \'pyre_page_title_text_alignment\', TRUE ) != \'default\' 
) {
    $alignment = get_post_meta( $post_id, \'pyre_page_title_text_alignment\', TRUE );
} elseif ( $smof_data[\'page_title_alignment\'] ) {
    $alignment = $smof_data[\'page_title_alignment\'];
}
如果if() 也不是elseif() 条件得到满足时,从不设置变量。可能存在缺少默认值的初始化:

$alignment = \'center\';
这应该放在上述代码谎言之上。

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请