/* =========================================================================
PAGE 10 — Blog (alias: blog) Item P10_CAT
Before Header: ecp_web.blog_page(:P10_CAT);
========================================================================= */
-- Featured (only when no category) Static ID: ecp_blog_featured Template: post-featured.html
select p.*, ecp_store.url_post(p.slug) url, ecp_store.url_blog(p.category_slug) cat_url, ecp_web.post_art(p.id) art_html
from ecp_v_posts p
where p.company_id = :G_COMPANY_ID and p.branch_id = :G_BRANCH_ID and p.status = 'PUBLISHED' and :P10_CAT is null
order by p.is_featured desc, p.published_at desc
fetch first 1 row only;
-- Grid Static ID: ecp_blog_grid Template: post-card.html
select p.*, ecp_store.url_post(p.slug) url, ecp_store.url_blog(p.category_slug) cat_url, ecp_web.post_art(p.id) art_html
from ecp_v_posts p
where p.company_id = :G_COMPANY_ID and p.branch_id = :G_BRANCH_ID and p.status = 'PUBLISHED'
and (:P10_CAT is null or p.category_slug = :P10_CAT)
and (:P10_CAT is not null or p.id <> (select id from ecp_v_posts where company_id = :G_COMPANY_ID and branch_id = :G_BRANCH_ID and status = 'PUBLISHED'
order by is_featured desc, published_at desc fetch first 1 row only))
order by p.published_at desc;
-- Category chips
select c.name_ar label, ecp_store.url_blog(c.slug) url,
case when c.slug = :P10_CAT then 'true' else 'false' end pressed
from ecp_post_categories c where c.company_id = :G_COMPANY_ID and c.branch_id = :G_BRANCH_ID order by c.sort_order;