从命令行调用wordpress?
我想知道是否有一种方法可以从 Linux 命令行从 WordPress 调用页面(不使用 wget
)。
我的意思是,我想要做的是这样的事情:
命令行:(调用一些 php 文件并传递相对 URL 作为参数)
$ php /var/www/something.php /my_blog/last_post
响应:
<div class='post'>
<!-- the last post content -->
<div>
我已经一直在谷歌搜索并查看 WordPress 文档,但我找不到任何东西。
感谢您抽出时间!
注意:如果您熟悉 Cakephp,我想要做的是类似 外壳和任务,但对于 WordPress
解决方案:
我在 WP 文件夹的根目录中创建了一个文件,名为 command.php:
<?php
include('wp-blog-header.php');
// call the WP functions and stuff, according to the parameters
?>
来调用它:
$ php command.php my_args
I'm wondering if there's a way to call a page from wordpress from the linux command line (without using wget
).
I mean, what i want is to do something like this:
The command line : (call some php file and pass a relative url as parameter)
$ php /var/www/something.php /my_blog/last_post
The response :
<div class='post'>
<!-- the last post content -->
<div>
I've been googling and looking in the Wordpress doc but i couldn't find anything.
Thanks for your time!
Note: If you're familiar with Cakephp, what i want is to do something like the Shell & Tasks but for wordpress
Solution:
I've created a file in the root of the WP folder, called command.php:
<?php
include('wp-blog-header.php');
// call the WP functions and stuff, according to the parameters
?>
to call it:
$ php command.php my_args
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,使用 wp-cli。可用命令;
Yes, using wp-cli. Available commands;
根据这个支持论坛入口,似乎没有WordPress的CLI界面。
似乎有一个 CLI 主题,但它已经过时并且不再处于积极开发状态。
但是,应该可以编写一个简单的 PHP 脚本,其中包含
wp-blog-header.php
并获取您需要的内容。我从未尝试过在 CLI 模式下包含wp-blog-header.php
,所以我不确定它是否会起作用,但它绝对值得一试。According to this support forum entry, there doesn't seem to be a CLI interface for WordPress.
There seems to have been a CLI theme but it is outdated and no longer under active development.
However, it should be possible to write a simple PHP script that includes
wp-blog-header.php
and fetches the content you need. I have never tried includingwp-blog-header.php
in CLI mode so I don't know for sure whether it will work, but it is definitely worth a shot.