1

我想在我的网站或页面上显示我的插件。我使用wordpress 2.3.2

我也授予了文件夹的权限。

例如,我编辑并更新了一个著名的插件 Holly dolly,但我不知道如何在前端显示..

我知道我必须打电话

// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );

但如何?

我尝试谷歌搜索,但没有任何完美的解决方案..

请帮我..

4

1 回答 1

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' );

?>
于 2012-05-30T12:29:55.337 回答