如果url包含php参数,则仅加载页面内容

时间:2016-05-17 21:13:04

标签: php wordpress

如果网址包含?mode=quick

,我正在尝试仅加载页面内容(阻止加载页眉菜单或页脚)

我已经尝试将以下内容添加到我的header.php的顶部,以尝试仅加载页面的内容,但它不起作用。

<?php
    if ($_GET['mode'] == 'quick'){
        the_content();
        exit();
    }
?>

能够通过在最后一行之前将以下代码添加到page.php来阻止页脚加载。

<?php
    if ($_GET['mode'] == 'quick'){
        exit();
    }
?>

<?php get_footer(); ?> // Last line

有没有办法做类似的事情,但也阻止加载标题?

4 个答案:

答案 0 :(得分:0)

索引页面     

require "pages/".$page.".php";

require_once("layouts/footer.php");
?>

的header.php

          $page = "home";
            if(isset($_GET['page'])){
                if($_GET['page']=='quick'){          
                  $page = $_GET['page'];
                }
            }

我希望它对你有所帮助

答案 1 :(得分:0)

保持简单! :)

if(!isset($_GET["quick"])) { loadHeader(); }

答案 2 :(得分:0)

您只需要将您的逻辑放在哪里:

<?php
    // Only show the header if 'mode' is NOT set or set to something not equal to 'quick'
    if (!isset($_GET['mode'] || $_GET['mode'] != 'quick'){
        get_header();
    }
    the_content();  //This is the one part that is ALWAYS shown
    if (!isset($_GET['mode'] || $_GET['mode'] != 'quick'){
        get_footer();
    }
?>

答案 3 :(得分:0)

我找到的解决方案是创建header.php的副本并将其重命名为header-empty.php

我修改了新头文件中的代码以将其删除。然后,如果url参数正确,我有条件地加载该标题。

Wordpress需要get_header()功能,所以我无法避免调用它。

page.php

的开头
<?php 
    if (isset($_GET['mode']) && $_GET['mode'] == 'quick'){
        get_header('empty');
    } else {
        get_header();
    }
?>

结束

<?php
    if (isset($_GET['mode']) && $_GET['mode'] == 'quick'){
        exit();
    }
?>
<?php get_footer(); ?> // Last line