如何在WordPress中添加PHP页面? [英] How can I add a PHP page to WordPress?

查看:595
本文介绍了如何在WordPress中添加PHP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的WordPress博客创建一个自定义页面,该页面将在其中执行我的PHP代码,同时保留整个网站CSS/theme/design的一部分.

I want to create a custom page for my WordPress blog that will execute my PHP code in it, whilst remaining a part of the overall site CSS/theme/design.

PHP代码将使用第三方API(因此我需要包含其他PHP文件).

The PHP code will make use of third-party APIs (so I need to include other PHP files).

我如何做到这一点?

N.B .:我没有与WordPress API交互的特定需求-除了包括某些其他PHP库之外,我还没有想要包含在WordPress页面中的PHP代码中的其他依赖项.因此,显然,不需要学习WordPress API的任何解决方案都是最好的解决方案.

N.B.: I do not have a specific need to interact with the WordPress API - apart from including certain other PHP libraries, I need I have no other dependencies in the PHP code I want to include in a WordPress page. So obviously any solution that didn't require learning the WordPress API would be the best one.

推荐答案

您无需与API进行交互或使用插件.

You don't need to interact with the API or use a plugin.

首先,在主题文件夹(在/wp-content/themes/themename/下)中复制post.phppage.php.

First, duplicate post.php or page.php in your theme folder (under /wp-content/themes/themename/).

将新文件重命名为templatename.php(其中templatename是您要称为新模板的名称).要将新模板添加到可用模板列表中,请在新文件顶部输入以下内容:

Rename the new file as templatename.php (where templatename is what you want to call your new template). To add your new template to the list of available templates, enter the following at the top of the new file:

<?php
/*
Template Name: Name of Template
*/
?>

您可以修改该文件(使用PHP)以包括其他文件或任何您需要的文件.

You can modify this file (using PHP) to include other files or whatever you need.

然后在您的WordPress博客中创建一个新页面,在页面编辑屏幕中,您会在右侧的 Attributes 小部件中看到一个 Template 下拉列表.选择您的新模板并发布页面.

Then create a new page in your WordPress blog, and in the page editing screen you'll see a Template dropdown in the Attributes widget to the right. Select your new template and publish the page.

您的新页面将使用templatename.php

来源: 查看全文

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