您可能注意到,加了一个”评分“的页面,用于显示得分靠前的文章.
我用了一个 GD Star Rating 的WP插件,装完效果如下, 可以让网友很轻松的为贴子或评论打分.
有点像 Facebook 的 赞或者 google plus 的 +1. 这些信息可以用来显示博客的热门文章.
做一个这样的页面其实很简单,不过你需要一个 能在贴子里加入 php 代码的插件,我用的是 Simple PHP Include 在 WP 插件控制里是可以找到的.
然后我们需要创建这样的一个页面(建议用PAGE,而不是POST)
然后这个 rate.php 就是我们需要创建的文件,需要放在主题的目录下,也就是 wp-content/themes/museum-core/rate.php
然后这个页面内容如下:
<?php global $wpdb; $query = " SELECT `p`.`ID`, `p`.`post_name` as `name`, `p`.`post_title` as `title`, `visitor_votes` + `user_votes` as `total_votes`, `visitor_votes`, `user_votes` FROM `".$wpdb->prefix."gdsr_data_article` as `da` INNER JOIN $wpdb->posts as `p` ON `da`.`post_id` = `p`.`ID` having `total_votes` > 0 order by `total_votes` desc limit 20 "; $results = $wpdb->get_results($query); if ($results) { $position = 0; foreach ($results as $toppost) { $position++; echo "#".$position."<a title='".htmlentities($toppost->title, ENT_QUOTES). "' href='/archives/".($toppost->ID)."/'>".$toppost->title."</a> - ". ($toppost->total_votes)." <BR>"; } } ?>
当然,如果你的WP文章的链接是其它类型的, 就必须自己修改那个 echo 语句输出正确的链接地址.我相信稍微懂一些PHP和 MySQL 的应该都很容易.
此文同步到英文博客.
GD Star Rating
loading...
本文一共 257 个汉字, 你数一下对不对.loading...
上一篇: CDN 内容加速
下一篇: 再见, 兢兢业业 的 Fasthosts
扫描二维码,分享本文到微信朋友圈
I know this feature, one WP theme developer even strongly suggested https://tumutanzi.com/guestbook/comment-page-8#comment-55248 me to use his plugin to get this feature, it is even displays at Google search results. I do not want to add this feature.
And especially implemented by plugin, which will not be my first choice.