Roots Discourse

Static Homepage with Blog posts section

Hello,
I am trying to create a static homepage custom template, with a structure like this:

  1. Hero
  2. Some images and texts
  3. [Blog Posts]
  4. Footer

What should be the correct behavior:

    <article @php post_class() @endphp>
        <header>
          <h2 class="entry-title"><a href="{{ get_permalink() }}">{!! get_the_title() !!}</a></h2>
          @include('partials/entry-meta')
        </header>
        <div class="entry-summary">
          @php the_excerpt() @endphp
        </div>
      </article>

Copied code from content.blade.php above that I use on my template-home.blade.php will show all posts with post type: post.
Like “Blog Post Title 1”, “Blog Post Title 2”, etc.


Current behavior:
Copied code above show posts with post type: page.
Like “Home”, “About”, etc.


What should I do to get the blog posts and attach it on my static homepage?

Solved with this solution:

Get the posts on Home Controller:

public function blog_posts(){
        $posts_per_page = 4;
        $query_args = [
            'post_type'           => 'post',
            'post_status'         => 'publish',
        ];

        $blog = get_posts($query_args);

        return $blog;
    }

And then call it from template:

{{ print_r($blog_posts) }}

This topic was automatically closed after 42 days. New replies are no longer allowed.