Home > Backend Development > PHP Tutorial > wordpress实现热评文章(一定时间内,指定目录)

wordpress实现热评文章(一定时间内,指定目录)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:48:38
Original
919 people have browsed it

想实现一个wordpress的热评文章(一定时间内,指定目录)功能,不想用插件,从网上找了很久,终于实现了2/3,为什么这么说,因为根据评论量排序和一定时间内这两个都实现了,但是指定目录这个还没实现。

代码贴上,这段代码写在wp模板的function.php内。

<code>function popularposts_with_comment($posts_num=10,$days=7,$display=ture) {
global $wpdb,$post; 
$output = '';      
$most_comment = $wpdb->get_results("
    SELECT ID , post_title , comment_count 
    FROM $wpdb->posts 
    WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) 
                    <a class="applist-img" href="'.get_permalink().'">'.get_the_post_thumbnail().'</a>'.
                    '<div class="app-des">
                    <h6><a href="'.get_permalink().'">'.$post_title. '
                    </a></h6>
                    <p>浏览次数:'.getPostViews(get_the_ID()).'
                    </p>
</div>';
    }
    echo $output;
</code>
Copy after login
Copy after login

}

回复内容:

想实现一个wordpress的热评文章(一定时间内,指定目录)功能,不想用插件,从网上找了很久,终于实现了2/3,为什么这么说,因为根据评论量排序和一定时间内这两个都实现了,但是指定目录这个还没实现。

代码贴上,这段代码写在wp模板的function.php内。

<code>function popularposts_with_comment($posts_num=10,$days=7,$display=ture) {
global $wpdb,$post; 
$output = '';      
$most_comment = $wpdb->get_results("
    SELECT ID , post_title , comment_count 
    FROM $wpdb->posts 
    WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) 
                    <a class="applist-img" href="'.get_permalink().'">'.get_the_post_thumbnail().'</a>'.
                    '<div class="app-des">
                    <h6><a href="'.get_permalink().'">'.$post_title. '
                    </a></h6>
                    <p>浏览次数:'.getPostViews(get_the_ID()).'
                    </p>
</div>';
    }
    echo $output;
</code>
Copy after login
Copy after login

}

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template