Please disable ad blocker to see the page.

Three Ways To Display Blog Post On Static Front Page

In most cases, a website owner want to use static front page and you know it's easy to set it, but if you want to display posts on that static front page then you have to do some more work.

How can you do this? I found three ways to accomplish this task, let's take a look on each way one by one.

By selecting the template

It is easy, all you need to choose a template when you create the page. All in all it is based on theme support.  

Follow the steps :
  • Go to the add new page.
Add static front page
  • Scroll down a bit and you will find a Page Attributes section, there select the Blog from the Template dropdown.
Page Attributes section
  • No need to write anything in the text editor. Publish the page.   

By creating new template

Many times you do not get Templates in Page Attributes section, so you have to  create a separate template file to display post on static front page. Let's see how.

1. Naming the template:

/**
 * Template Name: Blog
 */


 2. Add header

get_header();


3. Fetch the post and show them:

<div id="primary" class="site-content">
        <div id="content" role="main">
        <?php $myposts = get_posts( 'numberposts=-1&offset=$debut' ); //Argument for number of post
    foreach( $myposts as $post) : setup_postdata( $post ) ?>
        <h1 class="entry-title"><?php the_title(); ?></h1><br>
<?php the_post_thumbnail(); ?><br>
        <!-- Only display part of the post so the user has to click "More!" --><div class="entry-summary">
        <?php the_excerpt(); ?>

        <a href="<?php the_permalink(); ?>">More!</a></div><br><br>
    <?php endforeach; ?>
        </div><!-- # --><br><br>
    </div>


4. Add footer

get_footer();

5. Now go to the page which you want to opt for the Home and go with the same procedure of
selecting the template.

By plugin

Another and very comfortable way to display post is via plugin. You may search one yourself. I have found these two useful plugins:

Display Posts Shortcode - If you use this plugin, you will get a shortcode [display-post], simply add this to your static front page.
Display Posts Shortcode

 It will display a list of post link on front page.
 
Display Posts links

TPG Get Posts -This plugin provide enough options for post display like number of post, styling, category etc. To get the code, need to open its settings page. Basically [tpg_get_posts] is a shortcode to display post on your static front page.

TPG Get Posts


TPG Get Posts settings

In the article, I have shown three different methods to display post on static front page in WordPress also tried to explain basic code structure to create a page template. Hopefully it will help newbies to achieve goal.
Previous
Next Post »
0 Comment