代码:
//添加碎语功能 添加到主题的functions.php文件中 function git_shuoshuo() { $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, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'menu_icon' => 'dashicons-format-chat', 'hierarchical' => false, 'menu_position' => 4 , 'supports' => array( 'editor', 'author', 'comments', 'title' ) ); register_post_type('shuoshuo', $args); } add_action('init', 'git_shuoshuo'); //说说的固定连接格式 function custom_shuoshuo_link( $link, $post = 0 ){ if ( $post->post_type == 'shuoshuo' ){ return home_url( 'shuoshuo/' . $post->ID .'.html' ); } else { return $link; } } add_filter('post_type_link', 'custom_shuoshuo_link', 1, 3); function custom_shuoshuo_rewrites_init(){ add_rewrite_rule( 'shuoshuo/([0-9]+)?.html$', 'index.php?post_type=shuoshuo&p=$matches[1]', 'top' ); } add_action( 'init', 'custom_shuoshuo_rewrites_init' );
//在主题的page目录或者主题根目录新建文件:shuoshuo.php 代码为下方代码。 <?php /* template name: shuoshuo description: template for xiaoxiaowu.me xiaoxiaowu theme */ get_header(); ?> <style type="text/css"> .shuoshuo-content { padding: 15px 30px 15px 30px; min-height: 60px; background-color: #fbfdfb; position: relative; box-shadow: 0 0 3px RGBA(0,0,0,.15); color: #666; letter-spacing: .0625rem; margin-bottom: 20px; font-size: 15px; line-height: 30px; } .shuoshuo-meta { margin-top: 20px; text-align: right; letter-spacing: 0; } @media screen and (min-width: 1000px) { .mobileads, .shuoshuo-sjsj { display: none !important } } .zhutou { position: relative; top: -75px; margin: 35px 0 0 15px; float:left; } .shuoshuo li { display: block; padding: 8px 0; } </style> <div class="pagewrapper clearfix"> <aside class="pagesidebar"> <ul class="pagesider-menu"> <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?> </ul> </aside> <div class="pagecontent"> <header class="pageheader clearfix"> <h1 class="pull-left"> <a href="<?php%20the_permalink()%20?>"><?php the_title(); ?></a> </h1> <div class="pull-right"><!--百度分享 --> <?php deel_share() ?> </div> </header> <div class="shuoshuo"> <ul class="archives-monthlisting"> <?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=6 . '&paged=' . $paged); if (have_posts()) : while (have_posts()) : the_post(); $x = wp_trim_words( get_the_content(),80); ?> <li> <div class="shuoshuo-content"> <?php echo $x; ?><br/> <div class="shuoshuo-meta"><span ><i class="fa fa-user"></i> <?php the_author() ?>   (<?php the_time('Y年n月j日G:i'); ?>)   </span><a target="_blank" href='<?php the_permalink(); ?>' data-original-title="查看详情">查看详情 | 评论</a> </div> </div> </li> <?php endwhile;endif; ?> </ul> </div> </div> <?php deel_paging(); ?> <?php get_footer(); ?>
有时候想在博客发发牢骚,有时候看到一些喜欢的文章,但又和博客的内容方向不一样,这时候就需要动动手改博客了。
之前一直都是新建了一个名为博主随笔的分类目录,然后把说说和喜欢的文章发布在那,可是这样很影响博客呢,所以这2天给博客弄了个发布说说的功能。
代码已经贴在上方,部分地方需要自行根据你的wordpress主题来修改,自己弄的才是最适合自己的,以上代码只是分享出来给有同样想法的童鞋一个参考。
最终效果请点击下方查看:
博主碎语
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论