首先,在主题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增加网站公告功能》的一些看法。更多内容请查看本栏目更多内容!
自己2012年12月20日左右接触wordpress,至今曾经两个月。由于以前丝毫没有网站治理经历及编程才能,因而...
Hana Flv Player 是一个在 WordPress 中使用比拟宽泛的播放器插件, 该插件内置了5种媒体播放器,其播放文件...
很多时分咱们需求在给 WordPress 文章编辑器设置默许内容,比方把罕用的扫尾或许文章留意事项放出来,本文就...
缺点文件/{Path}/wp-includes/registration-functions.php 要害代码: —-> <?php /** * Deprecated. N...
随着搜寻引擎大兴, 陈列在前的网站引入大量流量. 无论是搜寻页面的广告还是查进去的后果, 与搜寻者的指标婚...
其实我集体并不是很喜爱这种摘要的显示形式,然而这个办法用起来比拟不便而已。 WordPress是有摘要性能...