为wordpress增加网站公告功能


本文整理自网络,侵删。

首先,在主题functions.php中增加下面的代码:


代码如下:

function wp_dashboard_GongGao() {
if($_POST && $_POST['update-GongGao'] == 1){
check_admin_referer('GongGao');
$GongGao = serialize($_POST['GongGao']);
update_option('GongGao',$GongGao) or add_option('GongGao',$GongGao);
}
?>
<form method="post" action="<?php echo add_query_arg ('time',time()); ?>">
<?php if($_POST && $_POST['update-GongGao'] == 1)echo '<p><span style="color:red;font-weight:bold;">更新公告成功</span></p>'; ?>
<?php $GongGao = unserialize(get_option('GongGao')); ?>
公告链接(留空则无链接):<input type="text" name="GongGao[link]" value="<?php if(isset($GongGao['link']))echo stripslashes($GongGao['link']); ?>" />
<p>公告信息
<textarea name="GongGao[content]" style="word-break:break-all;width:80%;" rows="4"><?php echo stripslashes($GongGao['content']); ?></textarea></p>
<input type="submit" class="button-primary" value="提交" />
<?php wp_nonce_field('GongGao'); ?>
<input type="hidden" name="update-GongGao" value="1" />
</form>
<?php
}
function my_wp_dashboard_setup() {
if(current_user_can('edit_themes'))wp_add_dashboard_widget('wp_dashboard_GongGao','网站公告','wp_dashboard_GongGao');
}
add_action('wp_dashboard_setup','my_wp_dashboard_setup');

阅读剩余部分

相关阅读 >>

基于wordpress主题制作的具体实现步骤

wordpress速度优化-nginx fastcgi_cache缓存加速

php 7.0.2 正式版发布

wordpress中自动激活插件的实现方法

python+wordpress制作小说站

解决安装wordpress时出现err_too_many_redirects重定向次数过多问题 font color=red原创font

wordpress回复评论文字的修改方法

win7 iis+php+mysql+wordpress安装说明

wordpress去除img标签的高度与宽度让图片自适应屏幕

wordpress迁移后图片地址错误问题的解决方法

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...