按长度限制下划线组

时间:2015-06-14 07:51:27

标签: underscore.js

我有很长的文章列表,我按类别分组,如何限制它,以便每个类别只有4个(或任何其他数字)项目?

我的意见是: enter image description here

我希望每个部分只有4篇文章

1 个答案:

答案 0 :(得分:2)

将对象值映射到自己的切片版本:

SELECT p1.*, wm2.meta_value 
FROM wp_posts p1 
LEFT JOIN wp_postmeta wm1 ON (
    wm1.post_id = p1.id
    AND wm1.meta_value IS NOT NULL
    AND wm1.meta_key = '_thumbnail_id'
)
LEFT JOIN
wp_postmeta wm2
ON (
    wm1.meta_value = wm2.post_id
    AND wm2.meta_key = '_wp_attached_file'
    AND wm2.meta_value IS NOT NULL
)
LEFT JOIN
wp_term_relationships wtr
ON (
    object_id=p1.id
)
WHERE
p1.post_status='publish'
AND p1.post_type='post'
AND object_id NOT IN (SELECT `object_id` FROM wp_term_relationships where `term_taxonomy_id`=81)
GROUP BY ID
ORDER BY p1.post_date DESC
LIMIT 0,10