给子比主题添加一个说说日记页面

起因:

  • 突然想写日记记录一下每天都干了啥,但是简短的话语用文章发布又感觉不太合适,在忆路吧博客看到了觉得很不错,就采纳了,记录下方法并做了小小的改动。
  • 使用教程:

使用教程

  • 首先在子比主题根目录新建文件func.php加入以下代码保存:
<?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','custom-fields','comments') ); register_post_type('shuoshuo',$args); }
 //指定说说文章模板
add_filter( 'template_include', 'include_template_function', 1 );
function include_template_function( $template_path ) {
    if ( get_post_type() == 'shuoshuo' ) {
        if ( is_single() ) {
            if ( $theme_file = locate_template( array ( 'shuoshuo.php' ) ) ) {
                $template_path = $theme_file;
            } else {
                $template_path = plugin_dir_path( __FILE__ ) . '/pages/shuoshuo.php';//自己修改文件路径
            }
        }
    }
    return $template_path;
}
/*说说点赞功能*/
add_action('wp_ajax_nopriv_bigfa_like', 'bigfa_like');
add_action('wp_ajax_bigfa_like', 'bigfa_like');
function bigfa_like(){
    global $wpdb,$post;
    $id = $_POST["um_id"];
    $action = $_POST["um_action"];
    if ( $action == 'ding'){
    $bigfa_raters = get_post_meta($id,'bigfa_ding',true);
    $expire = time() + 99999999;
    $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
    setcookie('bigfa_ding_'.$id,$id,$expire,'/',$domain,false);
    if (!$bigfa_raters || !is_numeric($bigfa_raters)) {
        update_post_meta($id, 'bigfa_ding', 1);
    } 
    else {
            update_post_meta($id, 'bigfa_ding', ($bigfa_raters + 1));
        }
    echo get_post_meta($id,'bigfa_ding',true);
    } 
    die;
}
  • 添加保存之后,就可以在网站后台左侧菜单栏,评论下面有个微语菜单,点击进去就可以实现发布和管理说说了。
  • 然后在子比主题pages目录下新建一个shuoshuo.php文件,然后添加下面代码保存。

附上效果图:

图片[1]-给子比主题添加一个说说日记页面-云上尘
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
良言一句三冬暖 . 恶语伤人六月寒
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容