将Php脚本转换为WordPress作为页面模板
我正在尝试将购买的php脚本(yougrabber)作为页面模板集成到WordPress中将Php脚本转换为WordPress作为页面模板,php,wordpress,Php,Wordpress,我正在尝试将购买的php脚本(yougrabber)作为页面模板集成到WordPress中 <?php /* Template Name: TESTIRANJE */ ?> <?php //error_reporting(E_ALL); //uncomment for development server define("BASE_PATH", str_replace("\\", NULL, dirname($_SERVER["SCRIPT_NAME"]) == "/" ?
<?php
/*
Template Name: TESTIRANJE
*/
?>
<?php
//error_reporting(E_ALL); //uncomment for development server
define("BASE_PATH", str_replace("\\", NULL, dirname($_SERVER["SCRIPT_NAME"]) == "/" ? NULL : dirname($_SERVER["SCRIPT_NAME"])) . '/');
require_once "core/router.php";
Router::init();
function __autoload($class) { Router::autoload($class); }
Router::route();
?>
该脚本作为独立网站运行良好。但当我尝试将其作为页面模板插入并打开时,会出现以下错误:
警告:require_once(application/config/routes.php):无法打开
流:中没有这样的文件或目录
/opt/lampp/htdocs/wordpress/wordpress/wp content/themes/twentyeven/yougrabber/core/router.php
在线55
致命错误:require_once():无法打开所需文件
'application/config/routes.php'(include_path=':/opt/lampp/lib/php')
在里面
/opt/lampp/htdocs/wordpress/wordpress/wp content/themes/twentyeven/yougrabber/core/router.php
在线55
我认为脚本应该加载到根目录中
当我把scripts index.php放在主题目录中并告诉wp它是一个页面模板时,它就是这样的
<?php
/*
Template Name: TESTIRANJE
*/
?>
<?php
//error_reporting(E_ALL); //uncomment for development server
define("BASE_PATH", str_replace("\\", NULL, dirname($_SERVER["SCRIPT_NAME"]) == "/" ? NULL : dirname($_SERVER["SCRIPT_NAME"])) . '/');
require_once "core/router.php";
Router::init();
function __autoload($class) { Router::autoload($class); }
Router::route();
?>
这似乎是路径问题,您在WordPress中使用它,所以您必须以WordPress的方式定义相关路径
使用get\u template\u directory\u uri()
获取主题路径,如果使用的是子主题,则使用get\u stylesheet\u directory\u uri()
如果您将脚本放在wp content/yourtheme/yourscriptdir
中,那么您的路径应该是:
require(get_template_directory_uri()。/yourscriptdir/core/router.php')代码>
编辑
生成警告的原因是您正在包含的文件使用了完整的URL,您可能会得到一些HTML,这就是我要求您使用dir结构的原因,尽管如果您在php.ini
文件中将allow\u URL\u include
更改为1
,它会起作用,但在live server上您会怎么做?要解决此问题,请在您的require中添加。/
,而不是像下面这样添加完整的url&看看是否有效:
在router.php中执行此操作
require('../application/config/routes.php')代码>你的目录结构是什么?@ArsalanMithani不确定我是否理解这个问题。我正在使用linux(fedora)。已在其上安装xampp…我要求您提供目录结构,您的文件应正确放置,wp content/theme/yourappfolder
然后将模板文件放置在主题根目录中。是一样的吗?index.php(问题中的代码)是我买的脚本。我在其中添加了前五行(告诉wp这是一个模板文件)。将整个脚本放在themes/twentyeven/yougrabber(php脚本)yourgrabber文件夹中,包含:index.php和文件夹:application、core、files。现在我将index.php(因为在themes/twentyeven/folder中已经有一个index.php)重命名为templateindex.php,并将其移动到themes/twentyeven/。现在显示错误:警告:require_once(core/router.php):无法打开流:第11行的/opt/lampp/htdocs/wordpress/wordpress/wp content/themes/twentyeven/templateindex.php中没有这样的文件或目录致命错误:require_once():无法打开所需的“core/router.php”(include_path=”。:/opt/lampp/lib/php)在第11行的/opt/lampp/htdocs/wordpress/wordpress/wp content/themes/twentyeven/templateindex.php中,我在哪里添加它?哪个文件?将requires替换为上述文件,确保路径正确。不,仍然不会更改错误。问题是它现在正在显示文件的正确路径,但仍然不起作用。
require( get_template_directory_uri() . '/directorypathtoscriptfiles');