如果已经发表评论,最近的帖子不会在帖子上方 [英] Most recent post does not come above post if there was already made an comment

查看:132
本文介绍了如果已经发表评论,最近的帖子不会在帖子上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Dianuj一个星期前解决了我的问题,当我问我如何可以在上方上获得最近的评论 >。这一切都很好,但昨天,当我测试它,我看到一个小问题,我不想在我的 Wordpress 网站。让我向你解释一下...

@Dianuj solved my issue a week ago, when I asked how I can get a recent comment above a post. That all worked very well, but yesterday, when I tested it, I saw a little issue, which I not want on my Wordpress site. Let me explain it to you...

如果有人对你评论前没有评论的帖子发表评论,那么此页面上的功能如何获取最新评论的信息post在Wordpress?将无懈可击。我感谢Dianuj让我的生活更轻松。

If someone makes a comment on a post that has none comments before you comment, then the function on this page How to get most recent commented post above new submitted post in Wordpress? will work flawlessly. I thank Dianuj for making my life easier.

当用户对ALREADY有评论的评论时,问题开始。例如,您对帖子发表第二个评论。在这种情况下,帖子标题不会上升,并在页面上显示他的面。这是一个大问题,我希望有人可以帮助我与这个链接上的片段

The problem starts when a user makes a comment on a post that ALREADY has a comment in it. So for instance, you make the second comment on a post. In that case, the post title won't go up and show 'his' face on the page. That is the big problem and I hope someone can help me out with the snippets that are on this link How to get most recent commented post above new submitted post in Wordpress?

PS:如何获得最新评论的帖子?对于懒惰的,这里它 - >

PS: for the lazy ones, here it goes -->

<?php
global $wpdb;
$results = $wpdb->get_results("    SELECT p.*,
    (CASE WHEN c.comment_date IS NULL THEN p.`post_date` ELSE c.comment_date END) order_column
     FROM `wp_posts` p
    LEFT  JOIN `wp_comments` c  ON (p.ID = c.`comment_post_ID` ) WHERE p.post_type='post' AND p.post_status='publish'
    GROUP BY p.ID
     ORDER BY order_column   DESC"); 
?>


推荐答案

在第一次出现 p.ID 时分组数据,所以最新的将被忽略在这里是获取所有数据与 ORDER BY ,然后将数据分组,以便最新的数据在那里。

In above case GROUP BY groups the data with first occurrence of the p.ID so the latest will be neglected here is the trick to get all data with the ORDER BY and then group the data so the latest one will be there

试试这个

SELECT * FROM (
SELECT   p.*,
       (CASE WHEN c.comment_date IS NULL THEN p.`post_date` ELSE c.comment_date END) AS order_column
     FROM `wp_posts` p
    LEFT OUTER JOIN `wp_comments` c  ON (p.ID = c.`comment_post_ID` ) WHERE p.post_type='post' AND p.post_status='publish' 
     ORDER BY order_column DESC 
   ) t GROUP BY ID  ORDER BY order_column DESC 

这篇关于如果已经发表评论,最近的帖子不会在帖子上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆