zoukankan      html  css  js  c++  java
  • wordpress代码实现文章内容回复可见

    1:首先进入主题文件夹所在目录找到functions.php文件,用编辑器打开,尽量不要用windows自带的文本编辑器,可用有代码提示的notepad++等。

    2:找个位置加入以下代码,在php结束前都行(?>之前):

    //加入回复可见功能
    function reply_to_read($atts, $content=null) {
    extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));
    $email = null;
    $user_ID = (int) wp_get_current_user()->ID;
    if ($user_ID > 0) {
    $email = get_userdata($user_ID)->user_email;
    //对博主直接显示内容
    $admin_email = "homgmail@foxmail.com"; //博主Email
    if ($email == $admin_email) {
    return $content;
    }
    } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
    $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
    } else {
    return $notice;
    }
    if (empty($email)) {
    return $notice;
    }
    global $wpdb;
    $post_id = get_the_ID();
    $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
     
    if ($wpdb->get_results($query)) {
    return do_shortcode($content);
    } else {
    return $notice;
    }
    }
    add_shortcode('reply', 'reply_to_read');
    //对博主直接显示内容结束

    3:ok完成了,在写文章时只要在需要隐藏的内容前后加上[*reply]内容[*/reply]就可实现回复可见(*号要去掉)如: [*reply]点此下载[*/reply] 也可以自定义隐藏提示信息,方法如下:[*reply notice="自定义的隐藏提示信息"]内容[*/reply]

    ps:如果不想用代码也可下载插件实现,如easy2hide插件,在wordpress后台插件菜单里搜索就可下载到。

  • 相关阅读:
    0523注册审核
    0520三级联动
    0519考试练习题
    0516ajax
    mysql 高级查询
    mysql
    HTML的格局与布局
    css样式表
    HTML表单
    HTML
  • 原文地址:https://www.cnblogs.com/homg/p/3344950.html
Copyright © 2011-2022 走看看