如何在wordpress首页中添加随机语录

1、修改插件Hello Dolly
这个插件是默认就有的。
注意:插件Hello Dolly在/wp-content/plugins/hello.php文件中。默认情况下无法修改hello.php文件,需用ftp软件将hello.php权限改成666,然后在wordpress后台修改文件。也可直接修改下载的hello.php然后上传。

在hello.php中添加以下语句:

// 在想要显示的地方加上 if(function_exists('show_dolly')) show_dolly(); 即可
function show_dolly() {
$chosen = hello_dolly_get_lyric();
echo $chosen;
}

其中hello_dolly_get_lyric()函数是插件中自带的。
还要修改里面的语录的内容。
然后保存,启用插件Hello Dolly。

2、修改模板index.php文件
如/wp-content/themes/twentytwentyone/index.php
注意:默认情况下无法修改index.php文件,参照上面hello.php的方法处理。

在get_header()函数后添加:

if(function_exists('show_dolly')) show_dolly();
或者
if(function_exists('show_dolly'))
{echo "<div class='default-max-width' style='text-align:center;background:#99cc66;'>每日一句:";show_dolly();echo "</div>";}

然后保存即可。

Leave a comment

Your email address will not be published. Required fields are marked *