当初,在浏览其他博友的站点时,发现侧边栏可以显示最新的说说心情,感觉很漂亮。想着,能不能在自己的博客侧边栏也显示。在自己的多次修改和测试下,终于可以显示了。
博主我使用的是懿古今的NANA主题,因此也是在此主题的基础上进行的修改适配。理论上,也适用其他WP主题,不过需要进行二次修改。
下面我将介绍下,大致的修改步骤及方法。
1、新建shuo.php,并复制下列代码后,上传至/inc/functions/文件夹下。
posts WHERE post_type = 'shuoshuo' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 0 , $number "; $posts = $wpdb->get_results($sql); $output = ""; foreach ($posts as $post){ $output .= "
".get_the_time('d')."/".get_the_time('m月')."
".$post->post_content."
2、复制下列代码,粘贴到/in/functions/widgets.php最下面。
// 心情说说:www.chyiyang.cn/52.html class shuoshuo_post extends WP_Widget { function __construct(){ parent::__construct( 'shuoshuo_post', '主题 心情说说', array('description' => '主题自带的心情说说小工具') ); } function widget($args, $instance) { extract($args); $title = apply_filters( 'widget_title', $instance['title'] ); echo $before_widget; if ( ! empty( $title ) ) echo $before_title . $title . $after_title; $number = strip_tags($instance['number']) ? absint( $instance['number'] ) : 5; ?>'5')); $number = strip_tags($instance['number']); ?>
3、在NANA主题functions.php下,加入如下代码。
// 说说心情 require get_template_directory() . '/inc/functions/shuo.php';4、将下列css样式粘贴到主题下的style样式里。
shuo_cat ul{padding:8px 15px 15px}.shuo_cat li{border-bottom:1px dotted #cbcbcb;padding:9pt 0}.shuo_cat li .time{float:left;width:70px;height:36px;line-height:36px;text-align:center;color:#616161;font-size:9pt;background:#f2f2f2;font-family:arial}.shuo_cat li .time span{display:inline-block}.shuo_cat li .time span.r{font-size:22px;width:25px;margin-right:2px;text-align:right}.shuo_cat li .time span.y{font-size:9pt;margin-left:2px;position:relative;bottom:1px}.shuo_cat li .title{height:auto;line-height:18px;overflow:hidden;font-size:14px;color:#3f3f3f;padding-left:6pt;white-space:normal}.shuo_cat li.hov{border-bottom:1px dotted #c01e22}.shuo_cat li.hov .time{background:#c01e22;color:#fff}.shuo_cat li.hov .title{color:#c01e22}好了,到此就弄完了。
添加此功能,需要站点有说说页面才可实现。
发表于8个月前 (05-23)
大神,如果是想在某个页面按“作者”来调用说说,请问怎么操作呢? 谢谢!
发表于8个月前 (05-23)
@依晨 不好意思,没有研究过,无法回答你,望见谅~~
发表于8个月前 (05-26)
@伊阳 Anyway, 还是谢谢你!