关于友链提交,想必大家都不陌生了,我就不多说啥了,鸣谢kratos主题的贡献!

目标

通过前端提交友链申请,并自动进入审查状态,管理员通过后端来对提交的友链进行管理。以Sakurario主题为例,我测试过webstack pro主题完美兼容,Sakurario有点瑕疵,其他就不知道了,测试完在下面留个言吧

前端

找到友情链接模板,Sakurario的模板文件是page-links.php,找到get_header();在下面添加代码

//这边接收post数据然后判断
if(!empty($_REQUEST)) {
    $webname=array_key_exists("webname",$_REQUEST)?$_REQUEST['webname']:"";
    $web=array_key_exists("web",$_REQUEST)?$_REQUEST['web']:"";
    $introduce=array_key_exists("introduce",$_REQUEST)?$_REQUEST['introduce']:"无";
    $avater=array_key_exists("avater",$_REQUEST)?$_REQUEST['avater']:"无";
    $mail=array_key_exists("mail",$_REQUEST)?$_REQUEST['mail']:"";
     if(!$webname) echo "<script type='text/javascript'>alert('名字不能为空!')</script>";
     else if(!$web) echo "<script type='text/javascript'>alert('网址不能为空!')</script>";
    else if(!$mail) echo "<script type='text/javascript'>alert('邮件地址不能为空!')</script>
   ";
    else{
//        获取到了需要的数据
        //获取所有的申请
        $application=esc_attr(get_option('application_list'));
        //欲添加的数据
        $add=$webname."!!]".$web."!!]".$introduce."!!]".$avater."!!]".$mail;
        update_option('application_list',$application.$add."]!!");
        echo "<script type='text/javascript'>alert('提交申请成功,请等待站长审核!审核通过后会发送邮件通知你!');window.history.back(-1); </script>";
        //发送邮件
        $to=get_bloginfo('admin_email');
        $subject = '有新的友链申请!';
        $message='名字:'.$webname.'<br/>网站地址:'.$web.'<br/>介绍:'.$introduce.'<br/>头像链接:'.$avater.'<br/>邮箱:'.$mail;
        $headers = 'Content-type: text/html';
        wp_mail($to,$subject,$message,$headers);
    }
}

然后找到 <?php echo get_link_items(); ?></div>下面添加如下代码

    <!-- 按钮触发模态框 -->                        <button class="btn btn-success" data-toggle="modal" data-target="#myModal" style="border-radius: 4px;margin-bottom: 15px">点击申请</button>
                                <!-- 模态框(Modal) -->
                                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content" style="margin-top: 30%;margin-right: 45%;">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                <h4>友链申请</h4>
                                            </div>
                                            <div class="modal-body">
                                                <form action=" " method="post" class="bs-example bs-example-form" role="form" style="text-align: center;">
                                                    <div class="input-group" >
                                                        <span class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></span>
                                                        <input type="text" name="webname" class="form-control" placeholder="名字">
                                                    </div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-link" aria-hidden="true"></i></span>
                                                        <input type="text" name="web" class="form-control" placeholder="网站地址">
                                                    </div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-id-card-o" aria-hidden="true"></i></span>
                                                        <input type="text" name="introduce" class="form-control" placeholder="个人介绍">
                                                    </div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-file-image-o" aria-hidden="true"></i></span>
                                                        <input type="text" name="avater" class="form-control" placeholder="头像链接"></div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-envelope-o" aria-hidden="true"></i> </span>
                                                        <input type="text" name="mail" class="form-control" placeholder="你的邮箱(添加后会通过邮箱通知你)">
                                                    </div>
                                                    <button type="submit" name="friend"  class="btn btn-info" style="border-radius: 10px;margin-top: 10px;">提交申请</button>

如果没有弹窗效果可以用下面这段代码

<h4>友链申请</h4>
                                            </div>
                                            <div class="modal-body">
                                                <form action=" " method="post" class="bs-example bs-example-form" role="form" style="text-align: center;">
                                                    <div class="input-group" >
                                                        <span class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></span>
                                                        <input type="text" name="webname" class="form-control" placeholder="名字">
                                                    </div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-link" aria-hidden="true"></i></span>
                                                        <input type="text" name="web" class="form-control" placeholder="网站地址">
                                                    </div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-id-card-o" aria-hidden="true"></i></span>
                                                        <input type="text" name="introduce" class="form-control" placeholder="个人介绍">
                                                    </div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-file-image-o" aria-hidden="true"></i></span>
                                                        <input type="text" name="avater" class="form-control" placeholder="头像链接"></div>
                                                    <div class="input-group">
                                                        <span class="input-group-addon"><i class="fa fa-envelope-o" aria-hidden="true"></i> </span>
                                                        <input type="text" name="mail" class="form-control" placeholder="你的邮箱(添加后会通过邮箱通知你)">
                                                    </div>
                                                    <button type="submit" name="friend"  class="btn btn-info" style="border-radius: 10px;margin-top: 10px;">提交申请</button>

预览

有弹窗效果的

后端

将我给的文件上传到主题目录的inc文件夹里面,下载地址:https://karensky.lanzous.com/ickwyud

找到fuction.php文件,在require 'update-checker/update-checker.php';前面添加如下代码

require_once(get_template_directory().'/inc/live2d/live2d.php');

后台预览

总结

这个是从kratos上面转移的,如有侵权,联系删除,如果有啥不适配的,在下面留个言,感谢!


一个爱好捣鼓网站的男孩纸!