WordPress:顶部菜单未显示在404页中

时间:2018-11-27 11:07:59

标签: php wordpress function menu

我在尝试将首页的顶部菜单添加到Wordpress-Journo edge-theme的404错误页面时遇到问题。

<?php
get_header();
?>



                <div class="edgtf-page-not-found">
                    <?php
                    $edgtf_title_image_404 = journo_edge_options()->getOptionValue( '404_page_title_image' );
                    $edgtf_title_404       = journo_edge_options()->getOptionValue( '404_title' );
                    $edgtf_subtitle_404    = journo_edge_options()->getOptionValue( '404_subtitle' );
                    $edgtf_text_404        = journo_edge_options()->getOptionValue( '404_text' );
                    $edgtf_button_label    = journo_edge_options()->getOptionValue( '404_back_to_home' );
                    $edgtf_button_style    = journo_edge_options()->getOptionValue( '404_button_style' );

                    if ( ! empty( $edgtf_title_image_404 ) ) { ?>
                        <div class="edgtf-404-title-image">
                            <img src="<?php echo esc_url( $edgtf_title_image_404 ); ?>" alt="<?php esc_attr_e( '404 Title Image', 'journo' ); ?>" />
                        </div>
                    <?php } ?>

                    <h1 class="edgtf-404-title">
                        <?php if ( ! empty( $edgtf_title_404 ) ) {
                            echo esc_html( $edgtf_title_404 );
                        } else {
                            esc_html_e( 'The page you are looking is not found', 'journo' );
                        } ?>
                    </h1>

                    <?php if ( ! empty( $edgtf_subtitle_404 ) ) { ?>
                        <h3 class="edgtf-404-subtitle">
                            <?php echo esc_html( $edgtf_subtitle_404 ); ?>
                        </h3>
                    <?php } ?>

                    <p class="edgtf-404-text">
                        <?php if ( ! empty( $edgtf_text_404 ) ) {
                            echo esc_html( $edgtf_text_404 );
                        } else {
                            esc_html_e( 'The page you are looking for does not exist. It may have been moved, or removed altogether. Perhaps you can return back to the site\'s homepage and see if you can find what you are looking for.', 'journo' );
                        } ?>
                    </p>

                    <?php
                        $button_params = array(
                            'link' => esc_url( home_url( '/' ) ),
                            'text' => ! empty( $edgtf_button_label ) ? $edgtf_button_label : esc_html__( 'Back to home', 'journo' ),
                            'type' => 'simple'
                        );

                        if ( $edgtf_button_style == 'light-style' ) {
                            $button_params['custom_class'] = 'edgtf-btn-light-style';
                        }

                        echo journo_edge_return_button_html( $button_params );
                    ?>

                    <div class="edgtf-grid edgtf-404-related">
                        <?php echo journo_edge_execute_shortcode('edgtf_layout1', array(
                            'posts_per_page'      => 8,
                            'column_number'       => 4,
                            'space_between_items' => 'normal',
                            'image_size'          => 'custom',
                            'custom_image_width'  => '800',
                            'custom_image_height' => '700',
                            'title_tag'           => 'h4',
                            'display_excerpt'     => 'no',
                            'display_comments'    => 'yes',
                            'display_like'        => 'yes'
                        )); ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php get_footer(); ?>
</body>
</html>

我试图在framework / modules / types / top-header / functions.php中查看顶部标题

但是无法调用该函数以显示404页的顶部菜单 尝试过寻求主题的支持,但是在此主题上,没有任何内容和Journo的支持几乎不存在。

希望有人对这个问题有一个答案或更简单的解决方案。

functions.php代码:

<?php

if ( ! function_exists( 'journo_edge_set_header_top_enabled_class' ) ) {
    function journo_edge_set_header_top_enabled_class( $classes ) {

        if ( journo_edge_is_top_bar_enabled() ) {
            $classes[] = 'edgtf-header-top-enabled';
        }

        return $classes;
    }

    add_filter( 'body_class', 'journo_edge_set_header_top_enabled_class' );
}

if ( ! function_exists( 'journo_edge_top_header_global_js_var' ) ) {
    function journo_edge_top_header_global_js_var( $global_variables ) {
        $global_variables['edgtfTopBarHeight'] = journo_edge_get_top_bar_height();

        return $global_variables;
    }

    add_filter( 'journo_edge_filter_js_global_variables', 'journo_edge_top_header_global_js_var' );
}

if ( ! function_exists( 'journo_edge_get_header_top' ) ) {
    /**
     * Loads header top HTML and sets parameters for it
     */
    function journo_edge_get_header_top() {
        $params = array(
            'show_header_top'                => journo_edge_is_top_bar_enabled(),
            'show_header_top_background_div' => journo_edge_get_meta_field_intersect( 'header_type' ) == 'header-box' ? true : false,
            'top_bar_in_grid'                => journo_edge_get_meta_field_intersect( 'top_bar_in_grid' ) == 'yes' ? true : false,
        );

        $params = apply_filters( 'journo_edge_filter_header_top_params', $params );

        journo_edge_get_module_template_part( 'templates/top-header', 'header/types/top-header', '', $params );
    }

    add_action( 'journo_edge_action_before_page_header', 'journo_edge_get_header_top' );
}

if ( ! function_exists( 'journo_edge_is_top_bar_enabled' ) ) {
    /**
     * Returns is top header area enabled
     *
     * @return bool
     */
    function journo_edge_is_top_bar_enabled() {
        $top_bar_enabled = journo_edge_get_meta_field_intersect( 'top_bar' ) === 'yes' ? true : false;

        if ( is_404() ) {
            $top_bar_enabled = false;
        }

        return apply_filters( 'journo_edge_filter_enabled_top_bar', $top_bar_enabled );
    }
}

if ( ! function_exists( 'journo_edge_get_top_bar_height' ) ) {
    /**
     * Returns top header area height
     *
     * @return bool|int|void
     */
    function journo_edge_get_top_bar_height() {
        if ( journo_edge_is_top_bar_enabled() ) {
            $top_bar_height_meta = journo_edge_filter_px( journo_edge_options()->getOptionValue( 'top_bar_height' ) );
            $top_bar_height      = ! empty( $top_bar_height_meta ) ? $top_bar_height_meta : 46;

            return $top_bar_height;
        } else {
            return 0;
        }
    }
}

if ( ! function_exists( 'journo_edge_get_top_bar_background_height' ) ) {
    /**
     * Returns top header area background height
     *
     * @return bool|int|void
     */
    function journo_edge_get_top_bar_background_height() {
        $top_bar_height_meta = journo_edge_filter_px( journo_edge_options()->getOptionValue( 'top_bar_height' ) );
        $header_height_meta  = journo_edge_filter_px( journo_edge_options()->getOptionValue( 'menu_area_height' ) );

        $top_bar_height = ! empty( $top_bar_height_meta ) ? $top_bar_height_meta : 46;
        $header_height  = ! empty( $header_height_meta ) ? $header_height_meta : 90;

        $top_bar_background_height = round( $top_bar_height ) + round( $header_height / 2 );

        return $top_bar_background_height;
    }
}

if ( ! function_exists( 'journo_edge_is_top_bar_transparent' ) ) {
    /**
     * Checks if top header area is transparent or not
     *
     * @return bool
     */
    function journo_edge_is_top_bar_transparent() {
        $top_bar_enabled      = journo_edge_is_top_bar_enabled();
        $top_bar_bg_color     = journo_edge_options()->getOptionValue( 'top_bar_background_color' );
        $top_bar_transparency = journo_edge_options()->getOptionValue( 'top_bar_background_transparency' );

        if ( $top_bar_enabled && $top_bar_bg_color !== '' && $top_bar_transparency !== '' ) {
            return $top_bar_transparency >= 0 && $top_bar_transparency < 1;
        } else {
            return false;
        }
    }
}

if ( ! function_exists( 'journo_edge_is_top_bar_completely_transparent' ) ) {
    /**
     * Checks is top header area completely transparent
     *
     * @return bool
     */
    function journo_edge_is_top_bar_completely_transparent() {
        $top_bar_enabled      = journo_edge_is_top_bar_enabled();
        $top_bar_bg_color     = journo_edge_options()->getOptionValue( 'top_bar_background_color' );
        $top_bar_transparency = journo_edge_options()->getOptionValue( 'top_bar_background_transparency' );

        if ( $top_bar_enabled && $top_bar_bg_color !== '' && $top_bar_transparency !== '' ) {
            return $top_bar_transparency === '0';
        } else {
            return false;
        }
    }
}

if ( ! function_exists( 'journo_edge_register_top_header_areas' ) ) {
    /**
     * Registers widget areas for top header bar when it is enabled
     */
    function journo_edge_register_top_header_areas() {
        register_sidebar(
            array(
                'id'            => 'edgtf-top-bar-left',
                'name'          => esc_html__( 'Header Top Bar Left Column', 'journo' ),
                'description'   => esc_html__( 'Widgets added here will appear on the left side in top bar header', 'journo' ),
                'before_widget' => '<div id="%1$s" class="widget %2$s edgtf-top-bar-widget">',
                'after_widget'  => '</div>'
            )
        );

        register_sidebar(
            array(
                'id'            => 'edgtf-top-bar-right',
                'name'          => esc_html__( 'Header Top Bar Right Column', 'journo' ),
                'description'   => esc_html__( 'Widgets added here will appear on the right side in top bar header', 'journo' ),
                'before_widget' => '<div id="%1$s" class="widget %2$s edgtf-top-bar-widget">',
                'after_widget'  => '</div>'
            )
        );
    }

    add_action( 'widgets_init', 'journo_edge_register_top_header_areas' );
}

if ( ! function_exists( 'journo_edge_top_bar_grid_class' ) ) {
    /**
     * @param $classes
     *
     * @return array
     */
    function journo_edge_top_bar_grid_class( $classes ) {
        if ( journo_edge_get_meta_field_intersect( 'top_bar_in_grid', journo_edge_get_page_id() ) == 'yes' &&
             journo_edge_options()->getOptionValue( 'top_bar_grid_background_color' ) !== '' &&
             journo_edge_options()->getOptionValue( 'top_bar_grid_background_transparency' ) !== '0'
        ) {
            $classes[] = 'edgtf-top-bar-in-grid-padding';
        }

        return $classes;
    }

    add_filter( 'body_class', 'journo_edge_top_bar_grid_class' );
}

if ( ! function_exists( 'journo_edge_get_top_bar_styles' ) ) {
    /**
     * Sets per page styles for header top bar
     *
     * @param $styles
     *
     * @return array
     */
    function journo_edge_get_top_bar_styles( $styles ) {
        $page_id      = journo_edge_get_page_id();
        $class_prefix = journo_edge_get_unique_page_class( $page_id, true );

        $top_bar_style = array();

        $top_bar_bg_color     = get_post_meta( $page_id, 'edgtf_top_bar_background_color_meta', true );
        $top_bar_border       = get_post_meta( $page_id, 'edgtf_top_bar_border_meta', true );
        $top_bar_border_color = get_post_meta( $page_id, 'edgtf_top_bar_border_color_meta', true );

        $current_style = '';

        $top_bar_selector = array(
            $class_prefix . ' .edgtf-top-bar'
        );

        if ( $top_bar_bg_color !== '' ) {
            $top_bar_transparency = get_post_meta( $page_id, 'edgtf_top_bar_background_transparency_meta', true );
            if ( $top_bar_transparency === '' ) {
                $top_bar_transparency = 1;
            }
            $top_bar_style['background-color'] = journo_edge_rgba_color( $top_bar_bg_color, $top_bar_transparency );
        }

        if ( $top_bar_border == 'yes' ) {
            $top_bar_style['border-bottom'] = '1px solid ' . $top_bar_border_color;
        } elseif ( $top_bar_border == 'no' ) {
            $top_bar_style['border-bottom'] = '0';
        }

        $current_style .= journo_edge_dynamic_css( $top_bar_selector, $top_bar_style );

        $current_style = $current_style . $styles;

        return $current_style;
    }

    add_filter( 'journo_edge_filter_add_page_custom_style', 'journo_edge_get_top_bar_styles' );
}

1 个答案:

答案 0 :(得分:2)

首先,检查您的htaccess文件并尝试更改永久链接。 如果您还没有完成此操作,请使用大型菜单WordPress插件,该插件与您的主题相同。 https://wordpress.org/plugins/megamenu/