在指定页面上隐藏链接

时间:2022-12-01 15:02:43

I have a footer file with a contact us link and copyright information. When I click the contact us link, it will go to the contact us page. I have my footer as a php file and just include in the respective page. I would like to hide the contact us link when in the contact us page. How can I go about doing this?

我有一个页脚文件,其中包含联系我们链接和版权信息。当我点击联系我们链接时,它将转到联系我们页面。我有我的页脚作为一个PHP文件,只是包含在相应的页面中。我想在联系我们页面中隐藏联系我们链接。我该怎么做呢?

footer.php

<?php
    echo '<footer class="footer">
              <div class="container">
                  <p class="text-muted"><a href="contactus.html">Contact Us</a></p>
                  <p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
              </div>
          </footer>';
?>

3 个解决方案

#1


0  

This will work:

这将有效:

$page_name=preg_replace('#^(.+[\\\/])*([^\\\/]+)$#', '$2', $_SERVER['PHP_SELF']);
if ($page_name!="about-us.html") {
    //display your link
}

#2


0  

You can do something like this. Instead of using echo, just write the html outside the <?php ?> tags and check the $_SERVER['REQUEST_URI'] and only show the link if it is not the contact page.

你可以做这样的事情。不要使用echo,只需在 标记之外写入html并检查$ _SERVER ['REQUEST_URI']并仅显示链接(如果它不是联系页面)。

<footer class="footer">
    <div class="container">
        <?php if (strpos($_SERVER['REQUEST_URI'], '/contactus.html') !== 0) { ?>
        <p class="text-muted"><a href="contactus.html">Contact Us</a></p>
        <?php } ?>
        <p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
    </div>
</footer>

#3


0  

you may try this ..

你可以试试这个..

<footer class="footer">
        <div class="container">
            <p class="text-muted"><a id="a" href="contactus.html">Contact Us</a></p>
            <p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
        </div>
    </footer>

and in javascript

并在JavaScript中

     var pathname = window.location.pathname;
        var appDomainEndding = 'yourdomain.com/app/'
        if (pathname.toLowerCase().indexOf("contactus.html") > -1 || 
            pathname.indexOf(appDomainEndding, pathname.length - appDomainEndding.length) > -1)
       // add class to hide the a tag 
{
document.getElementById("a").style.visibility = "hidden";
}

#1


0  

This will work:

这将有效:

$page_name=preg_replace('#^(.+[\\\/])*([^\\\/]+)$#', '$2', $_SERVER['PHP_SELF']);
if ($page_name!="about-us.html") {
    //display your link
}

#2


0  

You can do something like this. Instead of using echo, just write the html outside the <?php ?> tags and check the $_SERVER['REQUEST_URI'] and only show the link if it is not the contact page.

你可以做这样的事情。不要使用echo,只需在 标记之外写入html并检查$ _SERVER ['REQUEST_URI']并仅显示链接(如果它不是联系页面)。

<footer class="footer">
    <div class="container">
        <?php if (strpos($_SERVER['REQUEST_URI'], '/contactus.html') !== 0) { ?>
        <p class="text-muted"><a href="contactus.html">Contact Us</a></p>
        <?php } ?>
        <p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
    </div>
</footer>

#3


0  

you may try this ..

你可以试试这个..

<footer class="footer">
        <div class="container">
            <p class="text-muted"><a id="a" href="contactus.html">Contact Us</a></p>
            <p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
        </div>
    </footer>

and in javascript

并在JavaScript中

     var pathname = window.location.pathname;
        var appDomainEndding = 'yourdomain.com/app/'
        if (pathname.toLowerCase().indexOf("contactus.html") > -1 || 
            pathname.indexOf(appDomainEndding, pathname.length - appDomainEndding.length) > -1)
       // add class to hide the a tag 
{
document.getElementById("a").style.visibility = "hidden";
}