
打开你主题的目录,找到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”,页面内容里面随便输入你想要给留言者看的内容就行了。
WordPress的留言板是没必要安装插件的,只需要新建一个页面,起名为留言板或在线留言,然后输入一些说明,然后发布即可成为留言板,用户评论就相当于留言了。而且大部分主题都集成有留言板模板的,只需要在新建留言板页面时选择相应的留言板模板即可。新建一个guestbook.php文件,然后输入如下代码保存,保存时注意文件编码。<?php
/*
Template Name: Guestbook
*/
?>
<?php get_header()?>
<?php if (have_posts()) : the_post()update_post_caches($posts)?>
<div class="post" id="post-<?php the_ID()?>">
<h2><?php the_title()?></h2>
<div class="content">
<?php the_content()?>
<div class="fixed"></div>
</div>
</div>
<?php include('templates/comments.php')?>
<?php else : ?>
<div class="errorbox">
<?php _e('Sorry, no posts matched your criteria.', 'inove')?>
</div>
<?php endif?>
<?php get_footer()?>
保存之后上传到你的主题目录。再进入wordpress后台,新建一个页面,名称为“留言板”,模板选择你刚刚上传的guestbook之后保存就可以了
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)