如何让瘦框架与wordpress一起工作



我把这些代码放在主题文件"index.php"中我的php是5.3.8已将.htaccess(附带slim)放入wordpress文件夹,选项永久链接已关闭。

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

index.php

<?php get_header(); ?>
<?php
$app = new Slim();
$app->get('/', function ($test) {
    echo "hello";
});
$app->run();
?>
<?php get_footer(); ?>

我运行这个代码,页面是空白的铬控制台显示505错误

您还可以考虑添加slim框架作为插件,并开始从主题中调用所需的函数。

以下是Github上的一个项目:https://github.com/Botnary/wp-slim-framework

尝试将get_header()get_footer()调用移动到app->get函数内部。所以你的index.php文件应该是这样的。。。

<?php
require "Slim/Slim.php";
$app = new Slim();
$app->get('/', function() {     
    get_header();
    echo "hello";
    get_footer();
});
$app->run(); 
?>

在我的Slim应用程序中包括WordPresswp加载文件,为Slim打开了wp功能。

您还可以使用wordpress中的REST API。因此,您可以通过请求来调用这些方法,而不是将其作为导入库来调用。。。。。。有点脏,但有效的变通办法。

https://discourse.slimframework.com/t/adding-wordpress-within-slim-3/2213/4

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

index.php

<?php include('../../../wp-load.php'); ?>
<?php get_header(); ?>
<?php
$app = new Slim();
$app->get('/', function ($test) {
    echo "hello";
});
$app->run();
?>
<?php get_footer(); ?>

最新更新