有的时候不想发文章,想跟QQ空间一样写个心情吐槽,下面久伴带来一个wordpress实现说说功能
预览地址: https://jiubx.com/xinqing

教程
在主题functions.php文件添加以下代码
//新建说说功能 add_action('init', 'my_custom_init'); function my_custom_init() { $labels = array( 'name' => '说说', 'singular_name' => '说说', 'add_new' => '发表说说', 'add_new_item' => '发表说说', 'edit_item' => '编辑说说', 'new_item' => '新说说', 'view_item' => '查看说说', 'search_items' => '搜索说说', 'not_found' => '暂无说说', 'not_found_in_trash' => '没有已遗弃的说说', 'parent_item_colon' => '', 'menu_name' => '说说' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'exclude_from_search' =>true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => null, 'taxonomies'=> array('category','post_tag'), 'supports' => array('editor','author','title', 'custom-fields','comments') ); register_post_type('shuoshuo',$args); }
然后在主题更目录新建shuoshuo.php文件并添加以下代码进去
<?php /* */ get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <div id="shuoshuo_content"> <ul class="bsy_timeline"> <?php query_posts("post_type=shuoshuo&post_status=publish&posts_per_page=-1");if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <span class="author_tou"><img src="https://img.jiub.ren/wp-content/uploads/2018/11/QQ%E5%9B%BE%E7%89%8720181105103723.jpg" class="avatar" width="48" height="48"></span> <a class="bsy_tmlabel" href="javascript:void(0)"> <div></div> <div><?php the_content(); ?></div> <div></div> <div class="shuoshuo_time"><i class="fa fa-user"></i><?php the_author() ?><i class="fa fa-clock-o"></i><?php the_time('Y年n月j日G:i'); ?> </div> </a> <?php endwhile;endif; ?> </li> </ul> </div> </main> <!-- .site-main --> </div> <script type="text/javascript"> $(function () { var oldClass = ""; var Obj = ""; $(".bsy_timeline li").hover(function () { Obj = $(this).children(".author_tou"); Obj = Obj.children("img"); oldClass = Obj.attr("class"); var newClass = oldClass + " zhuan"; Obj.attr("class", newClass); }, function () { Obj.attr("class", oldClass); }) }) </script> <?php get_sidebar(); ?> <?php get_footer();?>
然后在你的主题样式表添加以下样式
2019年5月21日 上午10:07 9F
你好,请问这个代码还能使用吗?
2019年8月9日 下午3:50 B1
@ &M.佐铒钉﹖ 可以使用
2019年4月29日 下午1:07 8F
看看这个是否可以 感谢!
2019年2月18日 下午8:39 7F
支持
2019年1月31日 下午5:49 6F
试一试哟
2019年1月31日 下午5:46 5F
貌似见过这个页面
2019年1月11日 上午10:49 4F
dsdas好你好
2018年12月9日 下午2:36 3F
我不管的,我直接发没有标题的
2018年12月10日 下午7:43 B1
@ YIR 也可以哈
2018年12月4日 下午3:36 2F
其实个人觉得这个说说对于独立博客意义不大,像这种简短的心情语句直接发布在QQ或微信可能更好。
2018年12月10日 下午7:43 B1
@ 懿古今 折腾党
2018年12月4日 下午1:08 1F
说说,这对于博客来说是一个比较使用的功能!
2018年12月4日 下午1:09 B1
@ 弥雅尔尔 是的,有的时候发表一下心情状态啥的,另写一篇文章我觉得不适合