我已经为个人博客安装了WordPress,并且逐步将我多年来写的所有小网页内容移植到博客页面上。
这样的页面是http://www.projecttoomanycooks.co.uk/cgi-bin/memory/majorAnalysis.py,这是一个返回单词列表的简单python脚本-我想将该行为嵌入到wordpress页面中-有人可以为我指出正确的方向,以便在wordpress中以简单的方式运行python点吗?
编辑-在下面的精彩回答之后,我的工作还有很多……但不幸的是,那里还远远不够……
我有在服务器上执行的python ...
projecttoomanycooks server [~/public_html/joereddington/wp-content/plugins]#./hello.py
Hello World!
它与激活的插件在同一目录中...
python代码...具有以下代码...
#!/usr/bin/python
print("Hello World!")
的PHP:
<?php
/**
* Plugin Name: Joe's python thing.
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/
/*from http://wordpress.stackexchange.com/questions/120259/running-a-python-scri
pt-within-wordpress/120261?noredirect=1#120261 */
add_shortcode( 'python', 'embed_python' );
function embed_python( $attributes )
{
$data = shortcode_atts(
array(
'file' => 'hello.py'
),
$attributes
);
$handle = popen( __DIR__ . '/' . $data['file'], 'r');
$read = fread($handle, 2096);
pclose($handle);
return $read;
}