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

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

问题描述

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

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).

我该如何实现?

注意:我没有与 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.

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

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

来源:创建供全球使用的自定义页面模板

这篇关于如何将 PHP 页面添加到 WordPress?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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