首页CMSWordPress无需插件实现隐藏内容回复可见 提高互动率

WordPress无需插件实现隐藏内容回复可见 提高互动率

时间2024-05-22 20:26:04发布访客分类CMS浏览828
导读:关于WordPress提高用户互动的功能还是比较多的,比如我们需要输入密码访问隐藏内容,需要特定的权限会员才可以访问查看。以及我们看到隐藏内容回复可见,这个又找到案例可以试试记录下来。//文章内容回复可见 add_shortcode('r...

关于WordPress提高用户互动的功能还是比较多的,比如我们需要输入密码访问隐藏内容,需要特定的权限会员才可以访问查看。以及我们看到隐藏内容回复可见,这个又找到案例可以试试记录下来。

//文章内容回复可见  add_shortcode('reply', 'reply_to_read');
     function reply_to_read($atts, $content=null) {
      extract(shortcode_atts(array("notice" =>
     'p>
    温馨提示:此处内容需要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 = "admin@itbulu.com";
     //span style="color: #0000ff;
    ">
    博主Email/span>
  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 (emptyempty($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;
  }
  }
     

代码部分添加到功能页面,修改下里面的邮箱。

然后我们需要在合适的部分隐藏:

[reply]需要隐藏的内容[/reply]    

对于短代码,我们也可以通过"强化WordPress默认编辑器小工具按钮的办法(自定义快速工具栏)"效仿添加。

关于WP隐藏内容扩展阅读:

1、简单代码实现WordPress隐藏内容用密码才可显示

2、WordPress精简代码之删除/隐藏WordPress版本号方法

3、WordPress关注微信公众号获取验证码查看隐藏内容

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: WordPress无需插件实现隐藏内容回复可见 提高互动率
本文地址: https://pptw.com/jishu/665826.html
启动和关闭spark的方法是什么 div 高度自适应height

游客 回复需填写必要信息