用PHP完成留言板功能

用PHP完成留言板功能,第1张

留言表:留言ID、用户ID、内容、发表时间、修改时间(此字段可选)。

回复表:回复ID、留言ID、用户ID、内容、发表时间、修改时间(此字段可选)。

第一个用户ID是谁发表的留言,第二个用户ID是谁回复的留言,这样无限回复没问题,应该和你设计的差不多。

查询(查询某条留言的所有回复):

在回复表里查询所有该留言的回复记录(查询条件为留言ID),并按发表时间降序

回复内容表:

回复Id 回复内容

回复关联表:

回复内容id回复内容id

已私信

首先我们用dreamweaver新建一个PHP空白页面,在此页面顶部设置你要建的留言板的名称,代码如下,红色部分就是留言板的名称,可以自己随意取,建议用英文吧,不要纯中文。 <?php/*Template Name: liuyanban*/?>

打开你主题的目录,找到page.php页面,然后把里面的代码全部复制过来粘贴到我们第一步新建的留言板页面。

第一二步完成后代码如下: <?php/*Template Name: liuyanban*/?><?php get_header(); ?><?php if (have_posts()) : the_post(); update_post_caches($posts); ?><div id=“post-<?php the_ID(); ?>”><h2><?php the_title(); ?></h2><div><?php edit_post_link(__(‘Edit’, 'inove‘), '<span>’, '</span>‘); ?><?php if ($comments || comments_open()) : ?><span><a href=“#respond”><?php _e('Leave a comment’, 'inove‘); ?></a></span><span><a href=“#comments”><?php _e('Go to comments’, 'inove‘); ?></a></span><?php endif?><div></div></div><div><?php the_content(); ?><div></div></div></div><?php include('templates/comments.php’); ?><?php else : ?><div><?php _e(‘Sorry, no posts matched your criteria.’, 'inove‘); ?></div><div id=“comments”><?php comments_template(“,true); ?></div><?php endif?><?php get_footer(); ?>

在上面的代码里面加上评论调用函数 <?php comments_template(”,true); ?>

建立了页面不能忘记了美化啊,怎么弄呢?我们需要做的就是直接调用文章内容页评论的CSS样式。代码如下(此代码和single.php里面的一样,不知道的朋友直接去主题目录single.php里面找): <div id=“comments”><?php comments_template(“,true); ?></div>

最后得到的留言本代码如下,将此页面存为”liuyanban.php“: <?php/*Template Name: liuyanban*/?><?php get_header(); ?><?php if (have_posts()) : the_post(); update_post_caches($posts); ?><div id=”post-<?php the_ID(); ?>“><h2><?php the_title(); ?></h2><div><?php edit_post_link(__('Edit’, 'inove‘), '<span>’, '</span>‘); ?><?php if ($comments || comments_open()) : ?><span><a href=”#respond“><?php _e('Leave a comment’, 'inove‘); ?></a></span><span><a href=”#comments“><?php _e('Go to comments’, 'inove‘); ?></a></span><?php endif?><div></div></div><div><?php the_content(); ?><div></div></div></div><?php include('templates/comments.php’); ?><?php else : ?><div><?php _e(‘Sorry, no posts matched your criteria.’, 'inove‘); ?></div><div id=”comments“><?php comments_template(”,true); ?></div><?php endif?><?php get_footer(); ?>

最后到WordPress后台-页面-新建一个页面,命名“留言板”。给此页面选择模板“liuyanban”,页面内容里面随便输入你想要给留言者看的内容就行了。

单独网页:123.php

留言板:content.php

在123.php中插入留言板的位置上写

<?php

include "content.php"

?>

注意content.php的路径要正确,否则显示不出来。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/bake/11932576.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存