wordpress知更鸟主题增加说说/微语单页教程

77生活网 免费教程wordpress知更鸟主题增加说说/微语单页教程已关闭评论4,223阅读模式

wordpress知更鸟主题增加说说/微语单页教程

前言

本博客是从emlog博客系统转到wordpress系统的,在用emlog时还可以发些说说,转到wordpress后因为没有微语功能又不想单独发一篇文章来写说说。

教程

本教程来自络,首先在主题的functions.php里面加入以下代码:

  1. //说说
  2.      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文件放到你正在使用的主题根目录里把下面代码放入shuoshuo.php;

  1. <?php /*
  2.     Template Name: 说说
  3.     author: 77生活网
  4.     url: http://ww.77shw.com
  5.     */
  6.     get_header(); ?>
  7. <style type="text/css">
  8.     #shuoshuo_content {
  9.         background-color: #fff;
  10.         padding: 10px;
  11.         min-height: 500px;
  12.     }
  13.     /* shuo */
  14.     body.theme-dark .cbp_tmtimeline::before {
  15.         background: RGBA(255, 255, 255, 0.06);
  16.     }
  17.     ul.cbp_tmtimeline {
  18.         padding: 0;
  19.     }
  20.     div class.cdp_tmlabel > li .cbp_tmlabel {
  21.         margin-bottom: 0;
  22.     }
  23.     .cbp_tmtimeline {
  24.         margin: 30px 0 0 0;
  25.         padding: 0;
  26.         list-style: none;
  27.         position: relative;
  28.     }
  29.     /* The line */
  30.     .cbp_tmtimeline:before {
  31.         content: '';
  32.         position: absolute;
  33.         top: 0;
  34.         bottom: 0;
  35.         width: 4px;
  36.         background: RGBA(0, 0, 0, 0.02);
  37.         left: 80px;
  38.         margin-left: 10px;
  39.     }
  40.     /* The date/time */
  41.     .cbp_tmtimeline > li .cbp_tmtime {
  42.         display: block;
  43.         /* width: 29%; */
  44.         /* padding-right: 110px; */
  45.         max-width: 70px;
  46.         position: absolute;
  47.     }
  48.     .cbp_tmtimeline > li .cbp_tmtime span {
  49.         display: block;
  50.         text-align: right;
  51.     }
  52.     .cbp_tmtimeline > li .cbp_tmtime span:first-child {
  53.         font-size: 0.9em;
  54.         color: #bdd0db;
  55.     }
  56.     .cbp_tmtimeline > li .cbp_tmtime span:last-child {
  57.         font-size: 1.2em;
  58.         color: #9BCD9B;
  59.     }
  60.     .cbp_tmtimeline > li:nth-child(odd) .cbp_tmtime span:last-child {
  61.         color: RGBA(255, 125, 73, 0.75);
  62.     }
  63.     div.cbp_tmlabel > p {
  64.         margin-bottom: 0;
  65.     }
  66.     /* Right content */
  67.     .cbp_tmtimeline > li .cbp_tmlabel {
  68.         margin: 0 0 45px 65px;
  69.         background: #9BCD9B;
  70.         color: #fff;
  71.         padding: .8em 1.2em .4em 1.2em;
  72.         /* font-size: 1.2em; */
  73.         font-weight: 300;
  74.         line-height: 1.4;
  75.         position: relative;
  76.         border-radius: 5px;
  77.         transition: all 0.3s ease 0s;
  78.         box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  79.         cursor: pointer;
  80.         display: block;
  81.     }
  82.     .cbp_tmlabel:hover {
  83.         /* transform:scale(1.05); */
  84.         transform: translateY(-3px);
  85.         z-index: 1;
  86.         -webkit-box-shadow: 0 15px 32px rgba(0, 0, 0, 0.15) !important
  87.     }
  88.     .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel {
  89.         background: RGBA(255, 125, 73, 0.75);
  90.     }
  91.     /* The triangle */
  92.     .cbp_tmtimeline > li .cbp_tmlabel:after {
  93.         right: 100%;
  94.         border: solid transparent;
  95.         content: " ";
  96.         height: 0;
  97.         width: 0;
  98.         position: absolute;
  99.         pointer-events: none;
  100.         border-right-color: #9BCD9B;
  101.         border-width: 10px;
  102.         top: 4px;
  103.     }
  104.     .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel:after {
  105.         border-right-color: RGBA(255, 125, 73, 0.75);
  106.     }
  107.     p.shuoshuo_time {
  108.         margin-top: 10px;
  109.         border-top: 1px dashed #fff;
  110.         padding-top: 5px;
  111.     }
  112.     /* Media */
  113.     @media screen and (max-width: 65.375em) {
  114.         .cbp_tmtimeline > li .cbp_tmtime span:last-child {
  115.             font-size: 1.2em;
  116.         }
  117.     }
  118.     .shuoshuo_author_img img {
  119.         border: 1px solid #ddd;
  120.         padding: 2px;
  121.         float: left;
  122.         border-radius: 64px;
  123.         transition: all 1.0s;
  124.     }
  125.     .avatar {
  126.         -webkit-border-radius: 100% !important;
  127.         -moz-border-radius: 100% !important;
  128.         box-shadow: inset 0 -1px 0 #3333sf;
  129.         -webkit-box-shadow: inset 0 -1px 0 #3333sf;
  130.         -webkit-transition: 0.4s;
  131.         -webkit-transition: -webkit-transform 0.4s ease-out;
  132.         transition: transform 0.4s ease-out;
  133.         -moz-transition: -moz-transform 0.4s ease-out;
  134.     }
  135.     .zhuan {
  136.         transform: rotateZ(720deg);
  137.         -webkit-transform: rotateZ(720deg);
  138.         -moz-transform: rotateZ(720deg);
  139.     }
  140.     /* end */
  141. </style>
  142. </head>
  143. <body>
  144. <div id="primary" class="content-area" style="">
  145.     <main id="main" class="site-main" role="main">
  146.         <div id="shuoshuo_content">
  147.             <ul class="cbp_tmtimeline">
  148.                 <?php query_posts("post_type=shuoshuo&post_status=publish&posts_per_page=-1");if (have_posts()) : while (have_posts()) : the_post(); ?>
  149.                 <li> <span class="shuoshuo_author_img"><img src="https://www.mom1.cn/wp-content/uploads/2017/03/5201314_avatar-96x96.jpg" class="avatar avatar-48" width="48" height="48"></span>
  150.                     <a class="cbp_tmlabel" href="javascript:void(0)">
  151.                         <p></p>
  152.                         <p><?php the_content(); ?></p>
  153.                         <p></p>
  154.                         <p class="shuoshuo_time"><i class="fa fa-clock-o"></i>
  155.                             <?php the_time('Y年n月j日G:i'); ?>
  156.                         </p>
  157.                     </a>
  158.                     <?php endwhile;endif; ?>
  159.                 </li>
  160.             </ul>
  161.         </div>
  162.     </main>
  163.     <!-- .site-main -->
  164. </div>
  165. <script type="text/javascript">
  166.     $(function () {
  167.         var oldClass = "";
  168.         var Obj = "";
  169.         $(".cbp_tmtimeline li").hover(function () {
  170.             Obj = $(this).children(".shuoshuo_author_img");
  171.             Obj = Obj.children("img");
  172.             oldClass = Obj.attr("class");
  173.             var newClass = oldClass + " zhuan";
  174.             Obj.attr("class", newClass);
  175.         }, function () {
  176.             Obj.attr("class", oldClass);
  177.         })
  178.     })
  179. </script>
  180. <?php get_sidebar(); ?>
  181. <?php get_footer();?>

然后在wordpress后台新建单页模板选择说说,头像地址在代码里修改,在哪发说说你自己找,发说说不用填标题!!

继续阅读
我的微信
微信扫一扫
weinxin
我的微信
你领一次红包多一份动力
支付宝搜索7503319领取
weinxin
我的公众号
 
77生活网