banner



How To Create Separate Pages For Blogs On Wordpress

2 Ways of Creating Separate Blog Pages in WordPress

I. Using index.php as a blog template

This method is very simple. It is default functionality in WordPress, with no additional code. It is used on many websites.

You should know one thing: some themes doesn't have code for blogs in their index.php file, for such themes this method doesn't work. In that case I recommend you to look at the second method, you can also find it in this post.

Step 1. Creating a Blog Page

First, go to thePages > Add new, after that fill the title input field, I suppose it will be «Blog», and save the page.

creating blog page in WordPress admin

Step 2. Customizing Locations for Homepage and Blog Posts

Go to theSettings > Reading and set up a static page as the homepage and our blog page as a posts page.

Customizing locations for front page and posts page

Step 3. Add a Menu Item

This is an unnecessary step. If you have finished the second step, the blog will appears on the page URL, you just created. The blog page will also useindex.php file as the template.

Anyway, if your current theme supports menus, you can add this page to website menus. If you want to do this, go toAppearance > Menus, add blog page to any menu and save it.

II. Using Your Own Page Template for Blog Posts

This method allows you to create blog sections using your own page template. This way is good when you need to display posts with your own parameters. You can also create multiple blog sections with different query arguments.

So, let's begin.

Step 1. Creating Page Template

I suppose you already know how to do this, if you don't, then open your current theme folder and create a php file there. You can name it as your want, e.g.blog-template.php. Into this file add the following code:

              <?php /*  * Template name: Blog section template  */            

Step 2. Creating a Page

This step is similar to the first step in the first method, the only difference is that you should specify a page template in the «Page Attributes» section.

specify your blog section template

Step 3. Paging Navigation

Of course, we need a pagination for our blog section. You probably use some sort of plugins or your own function for these purposes. If something goes wrong, I recommend you to use WP-PageNavi plugin. I made some tests – this plugin works fine with the code from this tutorial.

Step 4. The Code for Page Template

This isjust an example without some of important template functions such asget_header() orget_footer(). But this template contains everything you need to test your blog page.

              <?php /*  * Template name: Blog section template  */ $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1; // get current page number $args = array( 	'posts_per_page' => get_option('posts_per_page'), // the value from Settings > Reading by default 	'paged'          => $current_page // current page ); query_posts( $args );   $wp_query->is_archive = true; $wp_query->is_home = false;   while(have_posts()): the_post(); 	?> 	<h2><?php the_title() /* post title */ ?></h2> 	<p><?php the_content() /* post content */ ?></p> 	<?php endwhile;   if( function_exists('wp_pagenavi') ) wp_pagenavi(); // WP-PageNavi function            
Misha Rudrastyh

Misha Rudrastyh

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me

Follow me on Twitter

How To Create Separate Pages For Blogs On Wordpress

Source: https://rudrastyh.com/wordpress/separate-blog-pages.html

Posted by: gonzalessiquene.blogspot.com

0 Response to "How To Create Separate Pages For Blogs On Wordpress"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel