用AI做了一个动态页面
AI时代不服不行,写代码嘎嘎好,还顺便纠正了我一个错误......
做的便签页面维护太费劲了,一直想优化一下,今天突发奇想,为何不做一个类似留言本的页面,屏蔽了非登陆用户可以发布留言功能就行了,正好我也尝试使用一下AI写代码看看怎么样。
第一步
把page.php当下来改名page-say.php(随便什么无所谓)然后在页面给他个命名:随便啥都行。
//TODO:先使用PHP定义变量实现,后期使用自定义主题实现 $x=25; /** * shuoshuo * @package custom */ Typecho_Widget::widget('Widget_Stat')->to($stat);?>
记得把页脚的调用评论文件名改成下面你重命名的文件
第二步
- 把评论文件comments.php(一般都是这个)当下来改名comments-1.php(随便啥名字)
用AI写的代码替换原代码。
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;?>
<article id="comments">
<?php $this->comments('comment')->to($comments); ?>
<!-- 只有登录用户才显示评论框 -->
<?php if($this->allow('comment') && $this->user->hasLogin()): ?>
<div id="<?php $this->respondId(); ?>" class="respond">
<div class="comment-head"><p>发表评论<span class="cancel-comment-reply"><?php $comments->cancelReply(); ?></span></p></div>
<form method="post" action="<?php $this->commentUrl() ?>" id="comment_form" class="comment-list">
<?php if($this->user->hasLogin()): ?>
<p>已作为管理员 <a href="<?php $this->options->profileUrl(); ?>"><?php $this->user->screenName(); ?></a> 登录,<a href="<?php $this->options->logoutUrl(); ?>" title="退出">点击退出</a></p>
<?php else: ?>
<ul class="login_meta">
<li>
<input type="text" name="author" id="author" placeholder="称呼*" value="<?php $this->remember('author'); ?>" required/>
<input type="text" name="mail" id="mail" placeholder="电子邮件*" value="<?php $this->remember('mail'); ?>" required/>
<input type="text" name="url" id="url" placeholder="网站 http://" value="<?php $this->remember('url'); ?>"/>
</li>
</ul>
<?php endif; ?>
<p><textarea rows="3" cols="50" name="text" id="textarea" placeholder="添加一条评论" required ><?php $this->remember('text'); ?></textarea></p>
<div><button type="submit" class="submit">发表评论</button></div>
</form>
<hr />
</div>
<!-- 未登录用户显示提示文字,不显示评论框 -->
<?php elseif($this->allow('comment')): ?>
<div class="comment-tip">请登录后发表评论</div>
<hr />
<?php endif; ?>
<!-- 评论列表正常显示 -->
<?php if ($comments->have()): ?>
<div class="comments_count"><?php $this->commentsNum(_t('当前暂无评论'), _t('仅有一条评论'), _t('已有 %d 条评论')); ?></div>
<div class="comments_box">
<?php $comments->listComments(); ?>
<?php $comments->pageNav(); ?>
</div>
<?php endif; ?>
</article>
发表评论