一直想用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('post',$args);
- }
如果你想你的说说让人评论的话在以上代码的supports
加上这个值'comments'
。具体如下
'supports' => array('editor','author','title', 'custom-fields','comments') );
然后后台就出现新建说说的功能了:
然后继续新建一个PHP文件,代码如下:
- <?php
- /* Template Name: 说说
- author: 流年
- url: http://lnaa.top
- */
- get_header(); ?>
- <div class="post">
- <ul class="archives-monthlisting">
- <?php query_posts("post_shuo&post_status=publish&posts_per_page=-1");if (have_posts()) : while (have_posts()) : the_post(); ?>
- <li><img src="http://lnaa.top/wp-content/themes/tinection/images/touxiang.gif" class="zhutou" alt="作者头像"><span class="tt"><?php the_time('Y年n月j日G:H'); ?></span><em></em>
- <div class="post-content"><?php the_content(); ?>
- <div class="post-meta"><span>— <?php the_author() ?></span></div>
- </div>
- <?php endwhile;endif; ?></li>
- </ul>
- </div>
- <?php get_footer();?>
如果你想在说说展示页面加入评论按钮 在以上代码的
- <span>— <?php the_author() ?></span>
的后面添加这段代码
- <span> | </span><span><a href="<?php the_permalink(); ?>#comments" title="评论" target="_blank" > 评论</a></span>
然后保存PHP文件把文件名改成page-post.php 然后上传到模板的目录
接着后台新建页面,模板选择 说说 ,然后保存。
然后你就可以在后台发布说说了,然后到你刚才新建的页面去看,是不是出来了?但是问题来了。。现在说说的样式很乱。。需要我们添加css。以下是我在使用的css。需要的自己复制,添加到style.css 里面即可。
- /*说样式*/
- .post {
- position: relative;
- padding: 10px 0;
- }
- .post li {
- padding: 8px 0;
- display: block;
- }
- .post-content {
- box-shadow: 0 0 3px RGBA(0,0,0,.15);
- background-color: #f2f2f2;
- border:1px #ccc solid;
- border-radius: 4px;
- font-size: 1.2em;
- line-height:1.5em;
- margin:0 150px 0 200px;
- letter-spacing: 1px;
- padding: 20px 20px 5px 30px;
- color: #666;
- min-height:60px;
- 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+, 文本行的任意字内断开 */
- }
- .post-content p{margin:0;}
- /*作者*/
- .post-meta {
- text-align: right;
- letter-spacing: 0px;
- margin-top:-10px;
- }
- /*时间*/
- .post .tt{margin: 35px 0 0 15px;float:left;font-size:0.7em;}
- .post li em{float:left;background:url("http://lnaa.top/wp-content/themes/tinection/images/bolangxian.png") no-repeat;width:50px;height:10px;margin:42px 0 0 28px;}
- .post li:hover .tt {color:#0c0;font-weight:bold;}
- /*头像*/
- .post .zhutou{border-radius: 50%;margin:25px 35px 0 5px;float:right;padding: 2px;border: 1px #ddd solid;display: block;transition: .5s;width: 40px;height: 40px;overflow:hidden;}
- .post li:hover .zhutou {
- transform: rotate(720deg);-webkit-transform: rotate(720deg);-moz-transform: rotate(720deg);border-color: #0c0;}
- /*前面的轴*/
- .post:before {
- height: 100%;
- width: 2px;
- background: #eee;
- position: absolute;
- left: 164px;
- content: "";
- top:0px;
- }
- .post-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 #0c0;
- }
- .post-content:after {
- position: absolute;
- top: 42px;
- bottom: 0px;
- left: -40px;
- background: #ccc;
- height: 8px;
- width: 8px;
- border-radius: 6px;
- content: "";
- }
- .post li:hover .post-content:after {
- background: #0c0;
- -webkit-transform: scale(1.3);
- -moz-transform: scale(1.3);
- -ms-transform: scale(1.3);
- -o-transform: scale(1.3);
- }
- .post li:hover .post-content:before {-webkit-transform: scale(1.3);
- -moz-transform: scale(1.3);
- -ms-transform: scale(1.3);
- -o-transform: scale(1.3);}
- /*后面的轴*/
- .post:after {
- height: 100%;
- width: 2px;
- background: #eee;
- position: absolute;
- right: 100px;
- content: "";
- top:0px;
- }
- .post-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 #0c0;
- }
- .post-meta:after {
- position: absolute;
- top: 44px;
- bottom: 0px;
- right: -54px;
- background: #ccc;
- height: 8px;
- width: 8px;
- z-index:2;
- border-radius: 6px;
- content: "";
- }
- .post li:hover .post-meta:after {
- background: #0c0;
- }
- @media screen and (max-width: 800px) {
- .post-content {margin:0 60px 0 70px;padding: 10px 10px 5px 10px;font-size:0.9em;}
- .post .tt{width:30px;font-weight:bold;margin: 30px 0 0 1px;font-size:0.5em;height: 20px;}
- .post li:hover .tt {color:#0c0;font-size:0.5em;}
- .post:before {left: 50px;}
- .post-content:before {left: -26px;top:30px;}
- .post-content:after {left: -24px;top:32px;}
- .post:after {right: 27px;}
- .post-meta:before {right: -39px;top:33px;}
- .post-meta:after {right: -37px;top:35px;}
- .post .zhutou{margin: 20px 8px 0 5px;}
- .post li em{float:left;width:39px;height:10px;margin:34px 0 0 -1px;}
- }
点击查看演示:http://lnaa.top/shuo 演示的说说页面经过后期的重新排版css 。。可能可上面的效果不一样。。
好了教程,完毕。
如果你遇到分页的问题 请查看这篇文章:解决WordPress自定义页面分页问题
香港 7F
大佬这个是最新的吗?我也来换上去试试
地球人 B1
@ 手机游戏网 这个不是最新的,很久之前的了….
陕西省西安市 6F
点击文章下方的说说演示,显示加载失败,检查一下。
地球人 B1
@ 清风美文 更新了。谢谢
广西 5F
点击说说演示失败
地球人 B1
@ boke112导航 已更新
北京市 4F
这个功能不错。。
地球人 3F
测试,,
地球人 B1
@ 流年 测试
广西 2F
博主,你好,boke112导航(博客导航站)特来拜会,发现贵站不错,已将贵站收录到博客导航的生活日记类,如有异议请留言哦!谢谢!PS:由于找不到贵站的留言板,所以就在此留言告知了,如造成困扰可删除本条评论,谢谢!
地球人 B1
@ boke112导航 谢谢 平时喜欢 逛博客 到哪都有你的身影 真勤快 嘿嘿
地球人 B1
@ boke112导航 友情链接已添加
北京市朝阳区 B1
@ boke112导航 到处都有你的脚印啊
湖南省湘西州 1F
抢个沙发支持博主
地球人 B1
@ 秦川博客 嘿嘿