Blog Post with a Featured Post

  • I've got a page of Blog posts displaying like this:

    You'll see I'm using two chunks of content, each split into "article-1" for the large featured story and "article-3" classes for the rest of the remaining article in a grid style.


    Two issues have come up:


    1. When using the pagination, the featured story stays large, but I'd like it to continue using the article-3 section. Does the pagination have to be for only perch_blog_custom?


    2. Since these perch_blog_custom instances are tapping the same Blog content, the Featured Article doubles in the Blog Articles. How can I filter that out when it's on the same page?

  • You could use a single call and handle most of this within a single template. Perch offers ways of changing content for the first item (or a variety of arguments) - for instance:

    Code
    1. <perch:if exists="perch_item_first"> Your html for the first post </perch:if>

    You could then use this to template them all in a single file and avoid needing to remove the post from the first call. Pretty sure that's how I've handled similar situations in the past.

  • You can do it all with a single perch_blog_custom() call like matdoidge suggested:



    Use template includes to make your life easier:


  • Ah, nice layout. Thanks guys!


    But when I test it, one thing is missing. The "Featured Article" should have a class of "article-1" but the rest of the "Blog Articles" should have a class of "article-3". When I implement your code above, it's only showing one or the other.


    So where do I add the "article-1" class for just the Feature Article?

  • But when I test it, one thing is missing. The "Featured Article" should have a class of "article-1" but the rest of the "Blog Articles" should have a class of "article-3". When I implement your code above, it's only showing one or the other.

    You can add it:


  • hus_hmd - wondering how I can make a slight change here.


    The first page has 13 posts showing - the "Featured" post and the remaining posts. But when you paginate, I'd like to showing 12 stories on the remaining pages since the spacing for 13 stories doesn't make sense on the remaining paginated pages and doesn't layout evenly.


    So is there a way to change the "count" for pages that aren't the first page?


    Again the code.


    post_in_featured_list.html


    And the display content:

    Code
    1. perch_blog_custom([
    2. 'count' => 13,
    3. 'sort' => 'postDateTime',
    4. 'template' => 'blog/post_featured_list.html',
    5. 'sort-order' => 'DESC',
    6. 'paginate' => true,
    7. 'section' => 'blog',
  • You can get the current page from the URL with perch_get('page') and conditionally set the count:




    Shorthand:


    PHP
    1. perch_blog_custom([
    2. 'count' => (perch_get('page') > 1) ? 12 : 13,
    3. 'paginate' => true,
    4. ]);