- 时间:2019-01-31 02:14 编辑:2KB 来源:2KB.COM 阅读:302
- 扫一扫,手机访问
- 分享
-
扫描二维码,分享到微信
打开微信
使用"扫一扫"
再点击微信界面右上角三个点标志
分享到微信朋友和朋友圈。
摘要:
对于类似发布各种活动通知或到期时间内容的wordpress站点,也许会需要这样一个功能:发布活动内容的时候设定活动的到期日期,当活动还没有 过期,网页显示“进行中”;当活动已过了设定的日期,网页则显示“已到期
对于类似发布各种活动通知或到期时间内容的wordpress站点,也许会需要这样一个功能:发布活动内容的时候设定活动的到期日期,当活动还没有 过期,网页显示“进行中”;当活动已过了设定的日期,网页则显示“已到期”或者不再显示该文章。有了这个功能,wordpress站长就不需要每次在活动 过期后再编辑文章,实现的方法可以通过wordpress内置的自定义字段。 创建日期自定义字段: 字段名称使用:expiration 设定日期的格式必须是:mm/dd/yyyy 00:00:00 如:01/01/2015 00:00:00 修改主题模板: 编辑当前使用的wordpress模板,修改文章主循环代码: <?php if (have_posts()) : while (have_posts()) : the_post(); $expiratiOntime= get_post_custom_values(&#39;expiration&#39;); if (is_array($expirationtime)) { $expirestring = implode($expirationtime); } $secOndsbetween= strtotime($expirestring)-time(); if ( $secondsbetween > 0 ) { ?> <div class="post" id="post-<?php the_ID();?>"> <h2><?php the_title();?></h2> <div class="entry"> <?php the_excerpt();?> </div> </div> <?php } endwhile; endif; ?> 上面代码的作用是如果当前时间超过设定的时间,文章则不显示。 编辑当前使用的主题模板,修改文章主循环代码: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID();?>"> <h2><?php the_title();?></h2> <div class="entry"> <?php the_excerpt();?> <?php $expiratiOntime= get_post_custom_values(&#39;expiration&#39;); if (is_array($expirationtime)) { $expirestring = implode($expirationtime); } $secOndsbetween= strtotime($expirestring)-time(); if ( $secondsbetween > 0 ) { echo &#39;进行中&#39;; }else { echo &#39;已过期&#39;; } ?> </div> </div> <?php endwhile; endif; ?> 上面代码的作用是如果当前时尚没有超过设定的时间内容中就显示“进行中”,否则就显示“已过期”。

2KB项目(www.2kb.com,源码交易平台),提供担保交易、源码交易、虚拟商品、在家创业、在线创业、任务交易、网站设计、软件设计、网络兼职、站长交易、域名交易、链接买卖、网站交易、广告买卖、站长培训、建站美工等服务