首先,在主题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增加网站公告功能》的一些看法。更多内容请查看本栏目更多内容!
上面是详细处理流程:1 首先关上phpadmin,从右边的表中抉择xx_opition2 在xx_opition中进行查问,在查问框...
其实完成短代码很简略,咱们只要要用到 WordPress 外面的一个函数就能够搞定短代码,外加本人的一个小函数,...
本文实例总结了wordpress随机调用显示文章的办法。分享给大家供大家参考。详细办法如下: 在wordpress中要随...
Fatal error: Call to undefined method wpdb_2::delete() in /home/*/public_html/wp-includes/o...
本文实例讲述了在WordPress治理页面底部自定义文字的办法,分享给大家供大家参考。详细完成办法如下: 把上面...
wp_title 函数在 WordPress 中是用来显示文章、页面、分类等等等等题目的一个函数,但在首页索引,该函数将...