不得不说,微博的确是好东西。

短小的篇幅,随时分享自己的想法。而正经的博文反而显得有点累赘了。

于是我也琢磨着给自己的这个小站加个这种类似说说的功能。

研究参考了网上大量的资料,自己慢慢改出了一个适合这个主题的页面

1.模板函数 (functions.php)

添加下列到functions.php中:

/*
 * 动态
 */
add_action('init', 'micro_live');
function micro_live()
{ $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('live',$args);
}

/*
 * 调用作者Gravatar头像
 */
function Get_author_Gravatar() { 
	$author_email_for_gravatar = get_the_author_meta(user_email);
	// 获取作者的邮箱地址并将其换成MD5哈希值,并设置图像的大小为64像素
	$authorgravatar = 'https://www.gravatar.com/avatar/' . md5($author_email_for_gravatar) . '?s=64';
	echo $authorgravatar;
} 

 

其中调用Gravatar头像的部分是为了获取自己的头像地址用于后面的动态头像部分,不使用固定的图片当头像哟~

具体参见这篇文章:根据用户邮箱显示Gravatar头像——如何获取WordPress用户信息

调用的时候使用以下代码就行了:

<img src="<?php Get_author_Gravatar(); ?>">

 

2.动态的页面

在主题里面新建个文件夹,名字随意,用来放模板。

最好是把主题里面自带的page.php复制一份,以此为基础来改,能更好地贴合主题风格

插入以下代码:

<div class="container" id="main-content">
	 <link href="/wp-content/themes/Blackoot/page-microlive/live.css" rel="stylesheet">
         <div class="live">
             <ul class="archives-monthlisting">
             <?php query_posts("post_type=live&post_status=publish&posts_per_page=-1");if (have_posts()) : while (have_posts()) : the_post(); ?>
			 <li><img src="<?php Get_author_Gravatar(); ?>" class="head" alt="作者头像"><span class="tt"><?php the_time('Y年n月j日G:i'); ?><br>@<?php the_author() ?></span>
                 <div class="live-content"><?php the_content(); ?><br/>
                 <div class="live-meta"></div>
                 </div>
             <?php endwhile;endif; ?>
             </li>
             </ul>
         </div>
</div>

 

更新后在后台菜单就能够看到了。

另外我们还需要自己建立一个css文件,如live.css

内容如下:

展开全部
.live {
position: relative;
margin: 50px 0;
}
.live li {
padding: 8px 0;
display: block;
}
.live-content {
box-shadow: 0 0 3px RGBA(0,0,0,.15);
background-color: #404040;
border:1px #b2b2b2 solid;
border-radius: 8px;
font-size: 1.2em;
line-height:1.6em;
margin:0 250px 0 200px;
letter-spacing: 0.2px;
padding: 20px 20px 5px 30px;
color: #f0f0f0;
min-height:80px;
position: relative;
 white-space: pre; /* CSS 2.0 */ 
 white-space: pre-wrap; /* CSS 2.1 */ 
 white-space: pre-line; /* CSS 3.0 */ 
 white-space: -pre-wrap; /* Opera 4-6 */ 
 white-space: -o-pre-wrap; /* Opera 7 */ 
 white-space: -moz-pre-wrap; /* Mozilla */ 
 white-space: -hp-pre-wrap; /* HP Printers */ 
 word-wrap: break-word; /* IE 5+, 文本行的任意字内断开 */
}
.live-content p{margin:0;}
/*作者*/
.live-meta {
text-align: right;
letter-spacing: 0px;
margin-top:-85px;
}
.toolbar{display:none}
/*时间*/
.live .tt{margin: 37px 0 0 15px;float:left;font-size:1em;}
.live li em{float:left;background:url("<?php GravatarForimg(); ?>") no-repeat;width:50px;height:10px;margin:42px 0 0 28px;}
.live li:hover .tt {color:#b8902b;font-weight:bold;}
/*头像*/
.live .head{border-radius: 50%;margin: 25px 135px 0 5px;float:right;padding: 2px;border: 1px #ddd solid;display: block;transition: .5s;width: 40px;height: 40px;overflow:hidden;}
.live li:hover .head {
transform: rotate(720deg);-webkit-transform: rotate(720deg);-moz-transform: rotate(720deg);border-color: #b8902b;}
/*前面的轴*/
.live:before {
height: 100%;
width: 2px;
background: #b2b2b2;
position: absolute;
left: 164px;
content: "";
top:0px;
}
.live-content:before {
position: absolute;
top: 40px;
bottom: 0px;
left: -42px;
background: #fff;
height: 12px;
width: 12px;
border-radius: 6px;
content: "";
box-shadow: inset 0 0 2px #b8902b;
}
.live-content:after {
position: absolute;
top: 42px;
bottom: 0px;
left: -40px;
background: #ccc;
height: 8px;
width: 8px;
border-radius: 6px;
content: "";
}
.live li:hover .live-content:after {
background: #b8902b;
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
-ms-transform: scale(1.3);
-o-transform: scale(1.3);
}
.live li:hover .live-content:before {-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
-ms-transform: scale(1.3);
-o-transform: scale(1.3);}
/*后面的轴*/
.live:after {
height: 100%;
width: 2px;
background: #b2b2b2;
position: absolute;
right: 200px;
content: "";
top:0px;
}
.live-meta:before {
position: absolute;
top: 42px;
bottom: 0px;
right: -56px;
background: #fff;
height: 12px;
width: 12px;
border-radius: 6px;
content: "";
z-index:2;
box-shadow: inset 0 0 2px #b8902b;
}
.live-meta:after {
position: absolute;
top: 44px;
bottom: 0px;
right: -54px;
background: #ccc;
height: 8px;
width: 8px;
z-index:2;
border-radius: 6px;
content: "";
}
.live li:hover .live-meta:after {
background: #b8902b;
}
@media screen and (min-width:1080px){
.live{width:1060px;margin:50px auto}
}
@media screen and (max-width: 800px) { 
.live-content {margin:0 60px 0 70px;padding: 10px 10px 5px 10px;font-size:0.9em;}
.live .tt{width:30px;font-weight:bold;margin: 30px 0 0 1px;font-size:0.5em;height: 20px;}
.live li:hover .tt {color:#b8902b;font-size:0.5em;}
.live:before {left: 50px;}
.live-content:before {left: -26px;top:30px;}
.live-content:after {left: -24px;top:32px;}
 
.live:after {right: 27px;}
.live-meta:before {right: -39px;top:33px;}
.live-meta:after {right: -37px;top:35px;}
 
.live .head{margin: 17px 5px 0 5px;}
.live li em{float:left;width:39px;height:10px;margin:34px 0 0 -1px;}
}

当然也是按照我的风格来的~

这样就ok啦

 

参考:如何使用Gravatar头像作为图标tang1314wuzuowei

还有言曌博客发布的风格也挺不错的,可是我没有用那个,还是放个在这里备用吧~

展开全部

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); }

 

php顺带css:

<?php /*
    Template Name: 说说
    author: 秋叶
    url: http://www.mizuiren.com/141.html
    */
    get_header(); ?>
<style type="text/css">
    #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);
    }
    /* 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://media.liuyanzhao.com/wp-content/uploads/2017/02/zhitianjiahui-e1489667385398.png" 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();?>

本文被阅读了:3,043次

作者头像
关于  Ailitonia

正因站在了巨人的肩膀上,才越发觉得自己渺小。不求成为巨人,但求与其同行。 把自己所见所闻,记录下来。

→查看所有由Ailitonia发布的文章