【问题标题】:How to redirect file to execute in header.php如何重定向文件以在 header.php 中执行
【发布时间】:2020-04-08 19:02:17
【问题描述】:

我正在尝试解决一个关于如何为字体真棒菜单栏设置动画以切换点击的问题。

我没办法,但为了解决这个问题,我在我的主题文件夹中创建了一个文件并将其命名为Menu Bars。在这个文件中,我放置了以下代码:

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" 
content="width=device- 
width, initial-scale=1">

<style>


.container {

display: inline-block;

cursor: pointer;

}

.bar1, .bar2, .bar3 {

width: 35px;

height: 5px;

background-color: #333;

margin: 6px 0;

transition: 0.4s;

}

.change .bar1 {

-webkit-transform: 
rotate(-45deg) 
translate(-9px, 6px);

transform: rotate(-45deg) 
translate(-9px, 6px);

}.change .bar2 {opacity: 
0;} .change .bar3 {

-webkit-transform: 
rotate(45deg) 
translate(-8px, -8px);

transform: rotate(45deg) 
translate(-8px, -8px);

}

</style>

</head>

<body>



<div class="container" 
onclick="myFunction(this)">

<div class="bar1"></div>

<div class="bar2"></div>

<div class="bar3"></div>

</div>

<script>

function myFunction(x) {

x.classList.toggle
("change");

}

</script>

</body>

</html>

然后我查看了我的 header.php 并将&lt;i class="fa fa-bars"&gt;&lt;/i&gt;替换为

<?php header("Location: 
home/qpgteouc/public_
html/wp- 
content/themes/shapel
y/Menu"); ?>

我以为这会重定向到这个文件`Menu Bars in location:

home/qpgteouc/public_
html/wp- 
content/themes/shapel
y/Menu

并执行文件,创建我想要的菜单栏动画。

实际发生的情况是该网站以too many redirects 为由拒绝加载。

我正在尝试做的事情是否可行,如果可以,我需要做什么?

这是我在提出有用的建议但仍然无法正常工作的情况。

<header id="masthead" class="site- 
header<?php echo get_theme_mod( 
'mobile_menu_on_desktop', true ) ? ' mobile-menu' : ''; ?>" role="banner">
    <div class="nav-container">
        <nav <?php echo $style; ?> id="site-navigation" class="main-navigation" role="navigation">
            <div class="container nav-bar">
                <div class="flex-row">
                    <div class="module left site-title-container">
                        <?php shapely_get_header_logo(); ?>
                    </div>
                    <div class="module widget-handle mobile-toggle right visible-sm visible-xs">

                        <?php require("home/qpgteouc/public_html/wp-content/themes/shapely/Menu_bars_"); ?>





                    </div>

                    <div class="module-group right">    
                        <div class="module left">


                            <?php shapely_header_menu(); ?>
                        </div>

                        <!--end of menu module-->
                        <div class="module widget-handle search-widget-handle hidden-xs hidden-sm">
                            <div class="search">
                                <i class="fa fa-search"></i>
                                <span class="title"><?php esc_html_e( 'Site Search', 'shapely' ); ?></span>
                            </div>
                            <div class="function">
                                <?php
                                get_search_form();
                                ?>
                            </div>
                        </div>
                    </div>
                    <!--end of module group-->
                </div>
            </div>

        </nav><!-- #site-navigation -->
    </div>

【问题讨论】:

  • @Utkanos 谢谢,那我该怎么办?它会知道因为文件extensionMenu最后...?
  • header("Location ... etc 告诉浏览器忘记它试图加载的页面并完全转到另一个页面。这与在同一页面中包含一些额外信息不同. 我不确定您是否真的要重定向到仅包含菜单而没有其他内容的页面?我怀疑您需要为主页中的菜单栏包含相关的 HTML 和 CSS您正在尝试加载。(当然,这样的包含文件不能有它自己的 html 头和正文标签,它们只能在整个最终文档中出现一次)
  • 为什么要重定向到文件?为什么你不需要("home/qpgteouc/public_html/wp-content/themes/shapely/Menu");
  • @ADyson 是的,请问我该怎么做?
  • 通过使用includerequire 命令将该文件的内容加载到当前脚本中。见php.net/manual/en/function.include.php

标签: php html css


【解决方案1】:

header("Location: *"); 总是重定向页面,因此浏览器每次都将您重定向到同一个站点。所以你必须使用includerequire。 示例

<?php require("home/qpgteouc/public_html/wp-content/themes/shapely/Menu"); ?>

【讨论】:

  • 尝试用您的代码替换我的代码,按照我上面概述的方式,但它只会破坏网站并报告“严重错误”
  • 是的...文件本身被称为Menu Bars但是当我检查路径时它是正确的,如上所列。它只是保存为读取文件。将其保存为其他扩展是否会产生影响?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-09
  • 1970-01-01
  • 1970-01-01
  • 2022-06-22
  • 2012-06-16
  • 2015-07-06
相关资源
最近更新 更多