wordpress模板制作过程中的最新评论调用
仿站知识 2014-10-31 1007 0 评论 admin

上次讲到在wordpress模板制作过程中的热评文章调用,现在给大家讲讲如何去调用最新评论?

1、在主题目录下新建文件夹includes
2、在includes文件夹中创建r_comment.php文件,并添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php if (get_option('swt_type') == 'Display') { ?>
<h3>最新评论</h3>
<div class="r_comment">
<ul>
    <?php
        global $wpdb;
        $my_email = get_bloginfo ('admin_email');
        $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,16) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' AND comment_author_email != '$my_email' ORDER BY comment_date_gmt DESC LIMIT 10";
        $comments = $wpdb->get_results($sql);
        $output = $pre_HTML;
        foreach ($comments as $comment) {
        $a= get_bloginfo('wpurl') .'/avatar/'.md5(strtolower($comment->comment_author_email)).'.jpg';
        $output .= "\n<li><img src='". $a ."'  alt=\"$comment->comment_author\" class='avatar'/>$comment->comment_author:<br /><a href=\"" . get_permalink($comment->ID) ."#comment-" . $comment->comment_ID . "\" title=\"查看 " .$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";
        }
        $output .= $post_HTML;
        $output = convert_smilies($output);
        echo $output;
    ?>
</ul>
</div>
    <?php { echo ''; } ?>
        <?php } else { include(TEMPLATEPATH . '/includes/r_comment2.php'); } ?>

3、在includes文件夹中创建r_comment2.php文件,并添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<h3>最新评论</h3>
<div class="r_comment">
<ul>
        <?php
            global $wpdb;
            $my_email = get_bloginfo ('admin_email');
            $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,16) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' AND comment_author_email != '$my_email' ORDER BY comment_date_gmt DESC LIMIT 10";
            $comments = $wpdb->get_results($sql);
            $output = $pre_HTML;
            foreach ($comments as $comment) {$output .= "\n<li>".get_avatar(get_comment_author_email(), 32).strip_tags($comment->comment_author).":<br />" . " <a href=\"" . get_permalink($comment->ID) ."#comment-" . $comment->comment_ID . "\" title=\"查看 " .$comment->post_title . "\">" . strip_tags($comment->com_excerpt)."</a></li>";}
            $output .= $post_HTML;
            $output = convert_smilies($output);
            echo $output;
        ?>
</ul>
</div>

4、在需要添加最新评论的地方添加以下调用代码:

1
<?php include('includes/r_comment.php'); ?>

5、在style.css文件中添加以下样式代码:

1
2
3
4
.r_comment {}
.r_comment ul {list-style-type:none;}
.r_comment li {line-height:24px; clear:both; height:48px; overflow:hidden;color: #777777;}
.r_comment ul li img.avatar {height:34px;float:left;padding:3px;margin:3px 4px 0 0;background:#fff;border: 1px solid #ddd;}

这样就完成了wordpress模板制作过程中的最新评论调用。

继续浏览有关: , , 的文章
版权声明:版权归 wp仿站之家 所有,转载请注明出处!
转载请保留链接: http://www.linw.net/362.html
联系wp仿站之家:5946394#qq.com (#改为@)
wp仿站微信公众号:linw_net
官网淘宝店:http://shop111710277.taobao.com/
wp仿站之家
手机扫一扫
进淘宝店铺选购主题

用心做最好的主题网站wp仿站之家

wp仿站之家是一个专业的wordpress仿站业务网站,提供wordpress主题模板下载以及seo网站优化服务,诚信经营,用心服务每一个客户,让您放心享受我们的优质服务。同时,也欢迎各位建站爱好者加入我们交流建站经验心得。

上一篇: 下一篇:

发表评论

服务咨询