使用多个模板显示页面内容 - WordPress [英] Display page content using multiple templates - WordPress

查看:30
本文介绍了使用多个模板显示页面内容 - WordPress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以有这样的页面:www.site.com/page/

Is it possible to have a page like: www.site.com/page/

并使用以下方式显示不同的模板化版本:

and show different templated versions using, say:

www.site.com/page/?template=default

www.site.com/page/?template=archive

...?

因此它检索相同的页面内容,但显示方式不同.

So it retrieves the same page content but displays it differently.

这可以用 WordPress 实现吗?这是标准的还是需要一些 tomhackery 来做到这一点?

Is this possible with WordPress? Is it standard or would need some tomhackery to do this?

谢谢

推荐答案

创建一个主"模板并将其分配给您的页面.主模板不包含任何布局信息——只是一组条件包含语句,用于根据 GET 变量选择真实"模板.主模板可能如下所示:

Create a 'master' template and assign it to your page. The master template doesn't contain any layout information—just a set of conditional include statements that selects the 'real' template based on the GET variable. The master template might look something like this:

<?php
switch ($_GET["template"]) {
    case "foo":
        include(TEMPLATEPATH . "/foo.php");
        break;
    case "bar":
        include(TEMPLATEPATH . "/bar.php");
        break;
    case "baz":
        include(TEMPLATEPATH . "/baz.php");
        break;
    default:
        include(TEMPLATEPATH . "/default_template.php");
        break;
}
?>

这篇关于使用多个模板显示页面内容 - WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆