作为一个个人的独立博客,说说怎么少得了,有时候我们写日志记心静,或者做通告,长不长,短不短的话语总是纠结怎么写成文章,但是为了人性化,像qq空间的说说,emlog的微语以及微博,都是把短语发挥到了极致,无奈wordpress没有这项功能,今天西安SEO就给大家说说“怎么给wordpress增加说说/微博功能”。
样式一:
首先在主题的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,?'supports'?=>?array('editor','author','title',?'custom-fields')?);
- register_post_type('shuoshuo',$args);
- }
其次,把下方代码保存为一shuoshuo.php文件上传到你正在使用的主题根目录里。
- <?php?/*
- ????Template?Name:?说说页面
- ????author:?沃森博客
- ????本文教程:http://wosn.net/540.html
- ????*/
- ????get_header();??>
- <style?type="text/css">
- ????#shuoshuo_content?{
- ????????background-color:?#fff;
- ????????padding:?10px;
- ????????min-height:?500px;
- ????????text-align:center;
- ????}
- ????/*?shuo?*/
- ????body.theme-dark?.cbp_tmtimeline::before?{
- ????????background:?RGBA(255,?255,?255,?0.06);
- ????}
- ????ul.cbp_tmtimeline?{
- ????????padding:?0;
- ????}
- ????div?class.cdp_tmlabel?>?li?.cbp_tmlabel?{
- ????????margin-bottom:?0;
- ????}
- ????.cbp_tmtimeline?{
- ????????margin:?30px?0?0?0;
- ????????padding:?0;
- ????????list-style:?none;
- ????????position:?relative;
- ????}
- ????/*?The?line?*/
- ????.cbp_tmtimeline:before?{
- ????????content:?'';
- ????????position:?absolute;
- ????????top:?0;
- ????????bottom:?0;
- ????????width:?4px;
- ????????background:?RGBA(0,?0,?0,?0.02);
- ????????left:?80px;
- ????????margin-left:?10px;
- ????}
- ????/*?The?date/time?*/
- ????.cbp_tmtimeline?>?li?.cbp_tmtime?{
- ????????display:?block;
- ????????/*?width:?29%;
- ????????padding-right:?110px;??*/
- ????????max-width:?70px;
- ????????position:?absolute;
- ????}
- ????.cbp_tmtimeline?>?li?.cbp_tmtime?span?{
- ????????display:?block;
- ????????text-align:?right;
- ????}
- ????.cbp_tmtimeline?>?li?.cbp_tmtime?span:first-child?{
- ????????font-size:?0.9em;
- ????????color:?#bdd0db;
- ????}
- ????.cbp_tmtimeline?>?li?.cbp_tmtime?span:last-child?{
- ????????font-size:?1.2em;
- ????????color:?#9BCD9B;
- ????}
- ????.cbp_tmtimeline?>?li:nth-child(odd)?.cbp_tmtime?span:last-child?{
- ????????color:?RGBA(255,?125,?73,?0.75);
- ????}
- ????div.cbp_tmlabel?>?p?{
- ????????margin-bottom:?0;
- ????}
- ????/*?Right?content?*/
- ????.cbp_tmtimeline?>?li?.cbp_tmlabel?{
- ????????margin:?0?0?45px?65px;
- ????????background:?#9BCD9B;
- ????????color:?#fff;
- ????????padding:?.8em?1.2em?.4em?1.2em;
- ????????/*?font-size:?1.2em;?*/
- ????????font-weight:?300;
- ????????line-height:?1.4;
- ????????position:?relative;
- ????????border-radius:?5px;
- ????????transition:?all?0.3s?ease?0s;
- ????????box-shadow:?0?1px?2px?rgba(0,?0,?0,?0.15);
- ????????cursor:?pointer;
- ????????display:?block;
- ????}
- ????.cbp_tmlabel:hover?{
- ????????/*?transform:scale(1.05);?*/
- ????????transform:?translateY(-3px);
- ????????z-index:?1;
- ????????-webkit-box-shadow:?0?15px?32px?rgba(0,?0,?0,?0.15)?!important
- ????}
- ????.cbp_tmtimeline?>?li:nth-child(odd)?.cbp_tmlabel?{
- ????????background:?RGBA(255,?125,?73,?0.75);
- ????}
- ????/*?The?triangle?*/
- ????.cbp_tmtimeline?>?li?.cbp_tmlabel:after?{
- ????????right:?100%;
- ????????border:?solid?transparent;
- ????????content:?"?";
- ????????height:?0;
- ????????width:?0;
- ????????position:?absolute;
- ????????pointer-events:?none;
- ????????border-right-color:?#9BCD9B;
- ????????border-width:?10px;
- ????????top:?4px;
- ????}
- ????.cbp_tmtimeline?>?li:nth-child(odd)?.cbp_tmlabel:after?{
- ????????border-right-color:?RGBA(255,?125,?73,?0.75);
- ????}
- ????p.shuoshuo_time?{
- ????????margin-top:?10px;
- ????????border-top:?1px?dashed?#fff;
- ????????padding-top:?5px;
- ????}
- ????/*?Media?*/
- ????@media?screen?and?(max-width:?65.375em)?{
- ????????.cbp_tmtimeline?>?li?.cbp_tmtime?span:last-child?{
- ????????????font-size:?1.2em;
- ????????}
- ????}
- ????.shuoshuo_author_img?img?{
- ????????border:?1px?solid?#ddd;
- ????????padding:?2px;
- ????????float:?left;
- ????????border-radius:?64px;
- ????????transition:?all?1.0s;
- ????}
- ????.avatar?{
- ????????-webkit-border-radius:?100%?!important;
- ????????-moz-border-radius:?100%?!important;
- ????????box-shadow:?inset?0?-1px?0?#3333sf;
- ????????-webkit-box-shadow:?inset?0?-1px?0?#3333sf;
- ????????-webkit-transition:?0.4s;
- ????????-webkit-transition:?-webkit-transform?0.4s?ease-out;
- ????????transition:?transform?0.4s?ease-out;
- ????????-moz-transition:?-moz-transform?0.4s?ease-out;
- ????}
- ????.zhuan?{
- ????????transform:?rotateZ(720deg);
- ????????-webkit-transform:?rotateZ(720deg);
- ????????-moz-transform:?rotateZ(720deg);
- ????}
- ????/*?end?*/
- </style>
- </head>
- <body>
- <div?id="primary"?class="content-area"?style="">
- ????<main?id="main"?class="site-main"?role="main">
- ????????<div?id="shuoshuo_content">
- ????????????<ul?class="cbp_tmtimeline">
- ????????????????<?php?query_posts("post_type=shuoshuo&post_status=publish&posts_per_page=-1");if?(have_posts())?:?while?(have_posts())?:?the_post();??>
- ????????????????<li>?<span?class="shuoshuo_author_img"><img?src="http://wosn.net/wp-content/themes/begin/img/touxiang/timg7.jpg"?class="avatar?avatar-48"?width="48"?height="48"></span>
- ????????????????????<a?class="cbp_tmlabel"?href="javascript:void(0)">
- ????????????????????????<p></p>
- ????????????????????????<p><?php?the_content();??></p>
- ????????????????????????<p></p>
- ????????????????????????<p?class="shuoshuo_time"><i?class="fa?fa-clock-o"></i>
- ????????????????????????????<?php?the_time('Y年n月j日G:i');??>
- ????????????????????????</p>
- ????????????????????</a>
- ????????????????????<?php?endwhile;endif;??>
- ????????????????</li>
- ????????????</ul>
- ????????</div>
- ????</main>
- ????<!--?.site-main?-->
- </div>
- <script?type="text/javascript">
- ????$(function?()?{
- ????????var?oldClass?=?"";
- ????????var?Obj?=?"";
- ????????$(".cbp_tmtimeline?li").hover(function?()?{
- ????????????Obj?=?$(this).children(".shuoshuo_author_img");
- ????????????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();?>
最后,打开后台 → 页面 → 新建页面,标题处输入“我的说说”,页面模板处选择我们的“说说页面”,然后直接点击发布页面。你会发现后台左侧栏目出现了一个说说栏目,点击它就可以发表说说了。
效果请看:http://wosn.net/shuoshuo.html
注意:在上方代码(即说说页面代码)150行处,替换自己的头像图片。
样式二(未测试):
操作方法同上,只是样式不同。
首先在主题的functions.php里面加入以下代码:
- /说说
- ?add_action('init',?'my_custom_init');?function?my_custom_init()?{?$labels?=?array(?'name'?=>?'说说',?'singular_name'?=>?'singularname',?'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,?'query_var'?=>?true,?'rewrite'?=>?true,?'capability_type'?=>?'post',?'has_archive'?=>?true,?'hierarchical'?=>?false,?'menu_position'?=>?null,?'supports'?=>?array('title','editor','author')?);?register_post_type('shuoshuo',$args);?}
其次,把下方代码保存为shuoshuo.php文件上传到你正在使用的主题根目录里。
- <?php?/*
- ???Template?Name:?说说页面
- ???author:?沃森博客
- ???url:?http://wosn.net/540.html
- ???*/
- ???get_header();??><link href="shuoshuo.css" rel="stylesheet"><div?class="shuoshuo">
- ????<ul?class="archives-monthlisting">
- ????<?php?query_posts("post_type=shuoshuo&post_status=publish&posts_per_page=-1");if?(have_posts())?:?while?(have_posts())?:?the_post();??>
- ????<li><span?class="tt"><?php?the_time('Y年n月j日G:i');??></span>
- ????<div?class="shuoshuo-content"><?php?the_content();??><br/><div?class="shuoshuo-meta"><span?>—<?php?the_author()??></span></div></div><?php?endwhile;endif;??></li>
- ????</ul>
- ???</div>
- ???<?php?get_footer();?>
把下方代码保存为shuoshuo.css文件上传到你正在使用的主题根目录里。
- ?.shuoshuo?{
- positionrelative;
- margin50px?0;
- }
- .shuoshuo?li?{
- padding8px?0;
- displayblock;
- }
- .shuoshuo-content?{
- box-shadow:?0?0?3px?RGBA(0,0,0,.15);
- background-color#f8f8f8;
- border:1px?#eee?solid;
- border-radius:?4px;
- font-size:?1em;
- line-height:2.3em;
- margin:0?150px?0?200px;
- letter-spacing1px;
- padding20px?20px?5px?30px;
- color#666;
- min-height:60px;
- positionrelative;
- ?whitewhite-spacepre;?/*?CSS?2.0?*/
- ?whitewhite-spacepre-wrap;?/*?CSS?2.1?*/
- ?whitewhite-spacepre-line;?/*?CSS?3.0?*/
- ?whitewhite-space:?-pre-wrap;?/*?Opera?4-6?*/
- ?whitewhite-space:?-o-pre-wrap;?/*?Opera?7?*/
- ?whitewhite-space:?-moz-pre-wrap;?/*?Mozilla?*/
- ?whitewhite-space:?-hp-pre-wrap;?/*?HP?Printers?*/
- ?word-wrap:?break-word;?/*?IE?5+,?鏂囨湰琛岀殑浠绘剰瀛楀唴鏂?紑?*/
- }
- .shuoshuo-content?p{margin:0;}
- /*浣滆??*/
- .shuoshuo-meta?{
- text-alignrightright;
- letter-spacing0px;
- margin-top:-85px;
- }
- .toolbar{display:none}
- /*鏃堕棿*/
- /*.shuoshuo?.tt{margin:?35px?0?0?15px;float:left;font-size:0.9em;}*/
- /*.shuoshuo?li?em{float:left;background:url("//www.100day.cc/wp-content/themes/frontopen2_v1.5.04.15/images/bolangxian.png")?no-repeat;width:50px;height:10px;margin:42px?0?0?28px;}*/
- /*.shuoshuo?li:hover?.tt?{color:#0c0;font-weight:bold;}?*/
- /*澶村儚*/
- .shuoshuo?.zhutou{border-radius:?50%;margin25px?35px?0?5px;float:rightright;padding2px;border1px?#ddd?solid;displayblock;transition:?.5s;width40px;height40px;overflow:hidden;}
- .shuoshuo?li:hover?.zhutou?{
- transform:?rotate(720deg);-webkit-transform:?rotate(720deg);-moz-transform:?rotate(720deg);border-color#0c0;}
- /*鍓嶉潰鐨勮酱*/
- .shuoshuo:before?{
- height:?100%;
- width2px;
- background#eee;
- positionabsolute;
- left164px;
- content"";
- top:0px;
- }
- .shuoshuo-content:before?{
- positionabsolute;
- top40px;
- bottombottom0px;
- left:?-42px;
- background#fff;
- height12px;
- width12px;
- border-radius:?6px;
- content"";
- box-shadow:?inset?0?0?2px?#0c0;
- }
- .shuoshuo-content:after?{
- positionabsolute;
- top42px;
- bottombottom0px;
- left:?-40px;
- background#ccc;
- height8px;
- width8px;
- border-radius:?6px;
- content"";
- }
- .shuoshuo?li:hover?.shuoshuo-content:after?{
- background#0c0;
- -webkit-transform:?scale(1.3);
- -moz-transform:?scale(1.3);
- -ms-transform:?scale(1.3);
- -o-transform:?scale(1.3);
- }
- .shuoshuo?li:hover?.shuoshuo-content:before?{-webkit-transform:?scale(1.3);
- -moz-transform:?scale(1.3);
- -ms-transform:?scale(1.3);
- -o-transform:?scale(1.3);}
- /*鍚庨潰鐨勮酱*/
- .shuoshuo:after?{
- height:?100%;
- width2px;
- background#eee;
- positionabsolute;
- rightright100px;
- content"";
- top:0px;
- }
- .shuoshuo-meta:before?{
- positionabsolute;
- top42px;
- bottombottom0px;
- rightright:?-56px;
- background#fff;
- height12px;
- width12px;
- border-radius:?6px;
- content"";
- z-index:2;
- box-shadow:?inset?0?0?2px?#0c0;
- }
- .shuoshuo-meta:after?{
- positionabsolute;
- top44px;
- bottombottom0px;
- rightright:?-54px;
- background#ccc;
- height8px;
- width8px;
- z-index:2;
- border-radius:?6px;
- content"";
- }
- .shuoshuo?li:hover?.shuoshuo-meta:after?{
- background#0c0;
- }
- @media?screen?and?(min-width:1080px){
- .shuoshuo{width:1060px;margin:50px?auto}
- }
- @media?screen?and?(max-width800px)?{
- .shuoshuo-content?{margin:0?60px?0?70px;padding10px?10px?5px?10px;font-size:0.9em;}
- .shuoshuo?.tt{width:30px;font-weight:bold;margin30px?0?0?1px;font-size:0.5em;height20px;}
- .shuoshuo?li:hover?.tt?{color:#0c0;font-size:0.5em;}
- .shuoshuo:before?{left50px;}
- .shuoshuo-content:before?{left:?-26px;top:30px;}
- .shuoshuo-content:after?{left:?-24px;top:32px;}
- .shuoshuo:after?{rightright27px;}
- .shuoshuo-meta:before?{rightright:?-39px;top:33px;}
- .shuoshuo-meta:after?{rightright:?-37px;top:35px;}
- .shuoshuo?.zhutou{margin17px?5px?0?5px;}
- .shuoshuo?li?em{float:left;width:39px;height:10px;margin:34px?0?0?-1px;}
- }
最后,打开后台 → 页面 → 新建页面,标题处输入“我的说说”,页面模板处选择我们的“说说页面”,然后直接点击发布页面。
注:如果不想富媒体说说,单纯地写文字的话,可以把最后一段代码中的<?php the_content(); ?>改成<?php the_title(); ?>,这样以后发表说说只要填写标题就可以了,查找起来也比较方便。如果你用<?php the_content(); ?>,那么你发表说说的时候标题和内容要写成一样,以方便查找,如果你只填写内容,那么你在后台查看说说的时候,显示的列表全是无标题,对于修改比较麻烦。
评论