将代码另存为一个php文件,后台开启插件 post_content; // 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 ) ] );}
post_content; // 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 nihao() { $chosen = nihao_get_lyric(); echo "在header.php或index.php或footer.php等任何你想要的位置放入以下代码$chosen [MORE]
"; } // Now we set that function up to execute when the admin_notices action is called add_action( 'head_notices', 'nihao' ); // We need some CSS to position the paragraph function nihao_css() { echo " "; } add_action( 'head_notices', 'nihao_css' ); ?>
插件说明
原插件是直接将要显示的内容放在插件文件内,不方便编辑, 所以采用直接调用一个文章或者页面的内容的方式显示,插件代码17行显示的就是ID为2的发布内容。 $lyrics = get_post( 2 )->post_content; 演示地址:http://gaobukai.com/nihao