我想在我的网站或页面中显示我的插件。
我使用wordpress 2.3.2
我也允许使用文件夹。
例如,有一个着名的pluigin Holly dolly我编辑并更新了,但我不知道如何在前端展示..
我知道我必须致电
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );
但是如何?
我尝试使用谷歌搜索,但没有得到任何完美的解决方案..
请帮帮我..
答案 0 :(得分:2)
这就是我所做的 - 在插件文件夹中复制hello.php
文件并将其重命名为myhello.php
。
这是我的系统上正常运行的代码 -
<?php
/**
* @package myhello
* @version 1.6
*/
/*
Plugin Name: My Hello
Plugin URI: http://wordpress.org/extend/plugins/myhello/
Description: This is not just a plugin
Author: Swapnesh Sinha
Version: 1.6
Author URI: swapneshsinha.wordpress.com
*/
function myhello_get_lyric() {
/** These are the lyrics to Hello Dolly */
$lyrics = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
Dolly'll never go away
Dolly'll never go away
Dolly'll never go away again";
// Here we split it into lines
$lyrics = explode( "\n", $lyrics );
// And then randomly choose a line
return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
// This just echoes the chosen line, we'll position it later
function myhello() {
$chosen = myhello_get_lyric();
echo "<p id='dolly'>$chosen</p>";
}
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'myhello' );
// We need some CSS to position the paragraph
function dolly_css() {
// This makes sure that the positioning is also good for right-to-left languages
$x = is_rtl() ? 'left' : 'right';
echo "
<style type='text/css'>
#dolly {
float: $x;
padding-$x: 15px;
padding-top: 5px;
margin: 0;
font-size: 11px;
}
</style>
";
}
add_action( 'admin_head', 'dolly_css' );
?>