问题描述
我想调用我在 Wordpress 中编写的另一个 php 类中的函数.但是我对语法感到困惑,例如要获取页面上的标题,您只需调用 get_header();等等 但是我如何调用特定类中的函数?例如在 index.php 中,我想调用位于 test.php 中的名为 this_function() 的函数.这是什么语法?
I want to call a function which is in another php class that I wrote in Wordpress. However I'm confused about the syntax, e.g. to get the header on a page you just call get_header(); etc. But how do i call a function in a specific class? For example in index.php I want to call a function named this_function() which reside in say test.php. What is the syntax for this?
我怀疑它很简单,但语法不正确,也无法在线提供任何帮助.
I suspect it to be very simple, but I can't get the syntax right, and I can't any help online.
谢谢
推荐答案
首先使用 require_once()
来包含 test.php,即
First use require_once()
to include the test.php, i.e.
require_once("path\test.php");
然后你可以简单地调用 this-function()
就可以了.
Then you can simply call this-function()
and it will work.
您可以将其用作参考:http://www.php.net/manual/en/function.require.php
这篇关于在 Wordpress 中调用自定义 php 模板中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!