首先,在主题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');
增加这段代码之后,进入后盾首页就能找到一个要害,让咱们填写布告内容。
之后在前台如何调用呢?在需求之处应用上面的代码即可:
<?php $GongGao = unserialize(get_option('GongGao'));if(!empty($GongGao['content'])): ?>
<p id="site-gonggao"><?php echo ($GongGao['link'] ? '<a href="'.$GongGao['link'].'">' : '').$GongGao['content'].($GongGao['link'] ? '</a>' : ''); ?></p>
<?php endif; ?>
至于款式之类,可依据本身需要进行调整。
以上就是安达网络工作室关于《为wordpress增加网站公告功能》的一些看法。更多内容请查看本栏目更多内容!
在帮King改他的公家情侣博客模版~找了一些找了,总算是把工夫显示为想要的格局了。于是将取得的一些信息记下...
本文实例讲述了wordpress给文章生成二维码的办法。分享给大家供大家参考。详细完成办法如下: 最简略的调用...
一、评论提交超时: 大家可能会发现,在提交评论十分迟缓时最容易呈现“匿名”景象,这种状况次要...
作为知名建站零碎,WordPress在国际博客建站畛域一枝独秀,在cms建站方面也有着超强的人气,能够搭建各类型...
概述 最近买了台效劳器,预备搭建集体博客,来继续更新本人的博客, 环境 效劳器操作零碎:CentOS 7.0 ...
本文实例讲述了Wordpress将选中内容分享到新浪腾讯微博的办法。分享给大家供大家参考。详细办法如下: 1、引...