- Template Hierarchy of Custom Front Page
- Contextual Conditional Tags
- Configuration of front-page.php
Best Blog Themes
By default, WordPress shows your most recent posts in reverse chronological order on the front page of your site. Many WordPress users want a static front page or splash page as the front page instead. This “static front page” look is common for users desiring static or welcoming information on the front page of the site.
There are many template files that WordPress uses to display the Post post type. Any content dealing with a blog or its posts are within the Post post type. Index.php # Index.php. Index.php will display Post post types if there is no other template file in place. As stated in many places, every theme must have an index.php file to be valid. There are many template files that WordPress uses to display the Post post type. Any content dealing with a blog or its posts are within the Post post type. Going to cover several bases in my answer.:) If you are creating your own theme, and want to change the default presentation of some types of pages (e.g. The category archive page, or a single blog post page), then check out the diagram of the WordPress template hierarchy.It shows which files in your theme directory are used to display which types of post. For pages, the standard template is usually the aptly named page.php. Unless there is a more specific template file available (such as archive.php for an archive page), WordPress will use page.php to render the content of all pages on your website. Blog Page is a material design WordPress theme for bloggers. The theme is a perfect fit for all kind of blogs such as food blogs, travel journals, personal blogs many more. Blog Page is a fully responsive design that always remains mobile-friendly and will render perfectly on all devices. If you want to create awesome-looking content quickly.
The look and feel of the front page of the site is based upon the choices of the user combined with the features and options of the WordPress Theme.
Template Hierarchy of Custom Front Page Template Hierarchy of Custom Front Page
On the site front page, WordPress will always use the front-page.php template file, if it exists. If front-page.php does not exist, WordPress will determine which template file to use, depending on the user configuration of Settings > Reading >Front page displays, as follows:
- A static page: WordPress uses the Static Page template hierarchy:
- Your latest posts: WordPress uses the Blog Posts Index template hierarchy:
Custom Site Front Page TemplateCustom Site Front Page Template
To create a custom site front page template, include either of the following in the Theme:
- A Custom Page Template (e.g. template-featured.php for featured content)
Custom Blog Posts Index Page TemplateCustom Blog Posts Index Page Template
To create a custom blog posts index template, include the following in the Theme:
Use only the home.php template file for the blog posts index. Do not use a Custom Page Template (such as template-blog.php) for two reasons:
Wordpress Blog Page Layout
- When the static front page feature is configured properly, WordPress will not use a Custom Page Template to display the blog posts index, even if a Custom Page Template is assigned to the page designated as the “Posts page”. WordPress will only use either home.php or index.php.
- When the Custom Page Template is assigned to a static page other than the one designated as the “Posts page,” the blog posts index loop pagination will not work properly.
Contextual Conditional TagsContextual Conditional Tags
The Conditional Tagis_front_page() checks if the site front page is being displayed. Returns true when the site front page is being displayed, regardless of whether ‘Settings > Reading ->Front page displays’ is set to “Your latest posts” or “A static page”.
The Conditional Tagis_home() checks if the blog posts index is being displayed. Returns true when the blog posts index is being displayed: when the site front page is being displayed and ‘Settings > Reading ->Front page displays’ is set to “Your latest posts”, or when ‘Settings > Reading ->Front page displays’ is set to “A static page” and the “Posts Page” value is the current Page being displayed.
When the site front page is being displayed and ‘Settings > Reading ->Front page displays’ is set to “Your latest posts”, bothis_front_page() and is_home() will return true.
Configuration of front-page.phpConfiguration of front-page.php
If it exists, the front-page.php template file is used on the site’s front page regardless of whether ‘Settings > Reading ->Front page displays’ is set to “A static page” or “Your latest posts,” the Theme will need to account for both options, so that the site front page will display either a static page or the blog posts index. There are a few methods to do so.
Wordpress Blog Page Template Plugin
Conditional display within front-page.phpConditional display within front-page.php
One way to allow front-page.php to account for both options for ‘Settings > Reading ->Front page displays’ is to add a conditional inside of front-page.php itself, using get_option( 'show_on_front' ), get_home_template(), andget_page_template().
Method 1: including custom content directly within front-page.php:
Method 2: including any page template:
Filtering frontpage_templateFiltering frontpage_template
Another way to allow the site front page to display either a static page/custom content or the blog posts index, without adding conditional code within front-page.php, is to filter frontpage_template, by adding a filter callback to functions.php:
This method causes WordPress to bypass the front-page.php template file altogether when the blog posts index is being displayed.
Adding custom query loops to front-page.phpAdding custom query loops to front-page.php
If the front-page.php template file includes a default WordPress Loop, like so:
That loop applies to the post content of the static page assigned to ‘Settings > Reading ->Posts page’.
To display custom loops (latest blog posts, custom/featured content, etc.), add secondary loop queries using calls to WP_Query. For example, to show the 3 latest blog posts:
Static front pages are not intended to be paged. None of the WordPress Previous / Next page link functions work with a static front page. Pagination on a static front page uses the page query variable, not the paged variable. See the WP_Query for details.