php弹出公告,wordpress主题右下角jquery弹出公告

在HotStyle主题在集成了右下角弹出最新公告的功能,此功能可以通过后台主题选项轻松开启关闭,现在就其实现方法做以下描述。

这一功能的实现非常简单,其利用jquery的fadeTo或者Hide的功能。

1,加载jquery.js.

script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"/script

2,加载以下js代码:

script type="text/javascript"

$(document).ready(function() {

//$('#sitefocus').hide(0, 0);

//$('#sitefocus').fadeIn(1800, 0);

$('.bm_h a').click(function() {

//$('#sitefocus').hide();

//$('#sitefocus').fadeTo(500, 0);

$('#sitefocus').hide(600, 0);

return false;

});

});

/script

3,css格式。

style type="text/css"

.focus {

position:fixed;

rightright:5px;

bottombottom:5px;

z-index:300;

overflow:hidden;

width:250px;

border:1px solid #AAA;

padding:0 10px;

background:white;

}

.bm,.bn {

margin-bottom:10px;

}

.bm_h {

padding:0 10px;

height:40px;

border-bottom:4px solid #009AD9;

line-height:40px;

whitewhite-space:nowrap;

overflow:hidden;

}

.cl {

zoom:1;

}

.y {

float:rightright;

}

a {

color:#333;

text-decoration:none;

}

h1,h2,h3,h4,h5,h6 {

font-size:1em;

}

body,ul,ol,li,dl,dd,p,h1,h2,h3,h4,h5,h6,form,fieldset,.pr,.pc {

margin:0;

padding:0;

}

.bm_c {

background:white;

}

.bbda {

border-bottom:1px dashed #CDCDCD;

}

.cl {

zoom:1;

}

.xld dt {

padding:8px 0 5px;

font-weight:700;

}

.bm_c h2 a,.bm_c dt a {

padding-right:10px;

color:#4A4E52;

}

.focus dt a {

color:#0060A6;

font-size:12px;

}

.xi2,.xi2 a,.xi3 a {

color:#266CB5;

}

.xld dd {

margin-bottom:8px;

}

.hm {

text-align:center;

}

.ptn {

padding-top:5px!important;

}

a:hover,* a:hover {

color:#F60 !important;

}

/style

4,php和html代码调用最新公告。

?php

$loop = new WP_Query( array( 'post_type' = 'bulletin', 'posts_per_page' = 1 ) );while ( $loop-have_posts() ) : $loop-the_post();

?

div class="focus" id="sitefocus"

div class="bm"

div class="bm_h cl"

a href="#" class="y" title="关闭"关闭/a

h2临时公告/h2

/div

div class="bm_c"

dl class="xld cl bbda"

dt

a href="?php the_permalink(); ?" class="xi2" target="_blank"

?php the_title(); ?

/a

/dt

dd

?php echo mb_strimwidth(strip_tags(apply_filters( 'the_content', $post-

post_content)), 0, 68,"..."); ?

/dd

/dl

p class="ptn hm"

a href="?php the_permalink(); ?" class="xi2" target="_blank"查看 »/a

/p

/div

/div

/div

?php endwhile; ?

这里循环调用最新公告,由于此公告由主题集成,所以不具有统一性,请根据个人实际需要做修改。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是纯代码实现WordPress添加网站公告功能的 PHP 代码: ```php // 添加公告 function add_site_notice($notice_text) { $option_name = 'site_notice'; $option_value = $notice_text; update_option($option_name, $option_value); } // 显示公告 function show_site_notice() { $option_name = 'site_notice'; $notice_text = get_option($option_name); if ($notice_text) { echo '<div class="site-notice">' . $notice_text . '</div>'; } } // 在 WordPress 后台添加公告编辑框 function add_site_notice_editor() { $option_name = 'site_notice'; $notice_text = get_option($option_name); echo '<label for="' . $option_name . '">网站公告:</label>'; echo '<textarea id="' . $option_name . '" name="' . $option_name . '">' . $notice_text . '</textarea>'; } // 保存公告编辑框中的内容 function save_site_notice_editor() { $option_name = 'site_notice'; if (isset($_POST[$option_name])) { $notice_text = $_POST[$option_name]; update_option($option_name, $notice_text); } } // 在 WordPress 后台添加公告编辑框 add_action('admin_init', function() { add_settings_field( 'site_notice', '网站公告', 'add_site_notice_editor', 'general' ); register_setting('general', 'site_notice', 'save_site_notice_editor'); }); // 在 WordPress 前台显示公告 add_action('wp_footer', 'show_site_notice'); ``` 将上述代码添加到 WordPress 主题的 `functions.php` 文件中即可。其中,`add_site_notice()` 函数用于添加公告,`show_site_notice()` 函数用于显示公告,`add_site_notice_editor()` 函数用于在 WordPress 后台添加公告编辑框,`save_site_notice_editor()` 函数用于保存公告编辑框中的内容。最后,使用 WordPress 提供的 `add_settings_field()` 和 `register_setting()` 函数将公告编辑框添加到 WordPress 后台的“常规设置”中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值