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, '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('say、',$args); }
 //指定说说文章模板
add_filter( 'template_include', 'include_template_function', 1 );
function include_template_function( $template_path ) {
    if ( get_post_type() == 'say' ) {
        if ( is_single() ) {
            if ( $theme_file = locate_template( array ( 'says.php' ) ) ) {
                $template_path = $theme_file;
            } else {
                $template_path = plugin_dir_path( __FILE__ ) . '/pages/says.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目录”创建says.php(名称一定不要错)文件,加入以下代码

到此说说界面就完成了,是不是很简单呢?

细节修改:

1.换页按钮外框距底部太近----修改为距离30px

2.换页按钮外框圆角太大,与说说列表不和谐----修改为8px

图片[1] - WordPress添加“说说”页面 - 云晓晨CatchYXC

3.说说内容与标题距离太近----修改为20px,且文章内容与标题对其

图片[2] - WordPress添加“说说”页面 - 云晓晨CatchYXC

4.说说内文章英文名类型----修改名称为说说,与文章/帖子类型相似,更和谐

图片[3] - WordPress添加“说说”页面 - 云晓晨CatchYXC
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 共5条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片
    • 头像blogman0
    • 头像blogman0
    • 头像blogman0
    • 头像王芸子0
    • 头像王芸子0
    • 头像CatchYun0
    • 头像王芸子0
    • 头像王芸子0
    • 头像王芸子0
    • 头像王芸子0
    • 头像王芸子0