网站增加微言微语页面

好久没有折腾网站了,偶尔也只是发一些类似流水账似的文章。
并不是没事可写,有时因为是一两句的事感觉没必要写。
于是周末想着是不是该整一个类似朋友圈微博类的页面,用来写一下短心情类的。
参照网络上的方法,几经修改,终于完成了。传送门——-> 微言微语

1. 在主题的functions.php里面加入以下代码:

Code Source
//说说
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); }

2. 新建一个shuoshuo.php文件放到你正在使用的主题根目录里,把下面代码放入shuoshuo.php中:

Code Source
<?php /*
Template Name: 说说
author: 小王子
url: https://www.wanghao.me
*/
get_header(); ?>

<div id="primary" class="content-area" style="">
<main id="main" class="site-main" role="main">
<div id="shuoshuo_content">
<ul class="cbp_tmtimeline">
<?php $limit = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('post_type=shuoshuo&post_status=publish&showposts=' . $limit=10 . '&paged=' . $paged);
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li> <span class="shuoshuo_author_img"><?php echo get_avatar( get_the_author_meta( 'user_email' ) ,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>
</div>
<?php kratos_pages(3);?>
<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();?>

可以根据主题适当调整上述核心代码。

3. 加入 style CSS代码

Code Source
/*说说*/
#shuoshuo_content {
background-color: #fff;
padding: 10px;
min-height: 500px;
}
/* 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);
}

4. 在wordpress后台新建单页模板选择第2步建的说说模板。

5. 最后就发说说了,在哪里发不用我说了吧,记住不用填写标题。

现在待解决的问题就是“分页”了????

已解决!
另外增加了侧栏调用或单独的页面显示!

更多精彩可以访问导航中的微语了解!!!

那年 • 今日
写于2018-08-04 14:05
酸甜苦辣咸,五味调和,共存相生,百味纷呈。

赞助 点赞 1

Dr.Drunker, Dr., CFanLost, 林三, 虫虫, 塑胶跑道, 阿和等人对本文发表了13条热情洋溢的评论。
  • Dr. Drunker说道:
    有没有友情链接页面教程?
    1. 老王说道:
      回复 Dr. Drunker: 这个网上教程比较多,所以没有折腾! 我的那个页面看的上吗?如果需要我可以发给你!
      1. Dr.Drunker说道:
        回复 老王: 那好啊,谢谢啦,我学习一下
        1. 老王说道:
          回复 Dr.Drunker: 已发你邮箱,谢谢!
  • CFanLost说道:
    回访,没有更新啥 先走了
    1. 王子说道:
      回复 CFanLost: 因为要放假,最近闲事太多! 放假了吧? 祝节日快乐!
  • 林三说道:
    我看了下结果,觉得zblog也是可以很轻松实现这个说说功能的罢。国庆祝好!
    1. 王子说道:
      回复 林三: 简单的 HTML 加 CSS 而已,没难度撒! :razz:
  • 虫虫说道:
    我现在也在折腾PHP了。目前在帮朋友写项目
    1. 王子说道:
      回复 虫虫: 你是大师级的啦,给你一百个赞!
  • 塑胶跑道说道:
    这个功能非常实用
  • 阿和说道:
    不错,php都能折腾了! 你这微言微语也可以弄成我那样的,可以发图片视频,可以评论。
    1. 王子说道:
      回复 阿和: 貌似可以发,但如果整那么复杂就不如直接发博客了。:-)))....
  • 发表回复

    您的电子邮箱地址不会被公开。 必填项已用 * 标注