Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Best practice for building a custom front page

  • Hi,

    I hope to get a quick opinion on this one as digging through the forums and docs didn’t get me further.

    On my site, I am using the blog setting for the front page, so on my front page, the most recent posts are shown. I am using a custom Block template to style the “loop” and a custom layout to have a sidebar appear to its right.

    However, on the top of the page I want to show the most recent articles in a highlighted format, as shown in my mockup. This setup might also change based on device, so it might be fairly complex but I know it is achievable with the block editor.

    mockup

    My question is
    1. How to I hook in this custom styled block to my blog front page?
    2. How can I set an offset in the loop below, so the articles shown in the top block do not appear in the loop again. I know there is an offset setting in the “Query Loop” block, but as I am using a Content Template, I am not sure to achieve this.

    Thanks for some help!

  • Hi there,

    1. Just create a Block Element – Page Hero for this: https://share.zight.com/bLuQxAxX

    This would consist of 2 Query Loops.

    2. You can add a snippet like this:

    function custom_offset_posts( $query ) {
        // Check if it's the main query and if it's the blog page
        if ( $query->is_main_query() && $query->is_home() ) {
            // Set the offset value (adjust as needed)
            $offset = 5; // Change this to your desired offset
    
            // Modify the query to include the offset
            $query->set( 'offset', $offset );
        }
    }
    add_action( 'pre_get_posts', 'custom_offset_posts' );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

  • Thanks Fernando for this fast reply. Technically, this works perfectly.

    Regarding the CSS styling, I am having problems to customise the typography of the page hero block. E.g. the default h2 styling rules seem to overwrite the settings I do in the block editor. Is that a normal behaviour?

  • Hi there,

    can i see the page where the styles are being overwritten?

  • Hi David, sure. I have attached the URL below.

    In the top element you see on this page, I have for example set a font weight of 700 & font-size: 3rem in the block editor for the h2 class gb-headline gb-headline-0d139cc1 gb-headline-text

    But in the frontend, the global h2 style is applied.

    Thanks!

  • Duplicate the problem headline block and delete the original
    It will re-generate the unique CSS ID for that block.

    This kinda of thing can happen if you copy blocks between posts, eg. from a post to an element, they end up with the same ID and the last block on the page to load will get the dibs on the CSS.

  • Ah, got it. Thank you!

  • you’re welcome

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.