Mangcoding

icon chat
Yayan Kurnia Akbar - Wednesday, 5 March 2025 - 4 months ago

2 Ways to Create a Separate Blog Page in WordPress

single image
Photo By Aaron Burden on Unsplash
Link Mangcoding

A. Using index.php as a Blog Template

Creating a blog page using this method is very simple as it utilizes WordPress’s default functionality without complex additional code. This method is widely used on websites.

However, you should be aware that some themes do not have blog-related code in their index.php file. For such themes, this method will not work. In that case, Mangcoding recommends using the second method.

Step 1 – Creating a Blog Page

First, go to Pages >> Add New, then enter a title in the input field, for example, “Blog,” and save the page.

creat blog mangcoding

Step 2 – Adjusting and Selecting the Location for the Homepage and Blog Posts

Go to Settings > Reading, then set a static page as the homepage and select our blog page as the posts page.

reading mangcoding

Step 3 – Add Menu Item

This step can be skipped. If the second step is completed, the blog will appear at the URL of the page you just created. The blog page will also use the index.php file as a template.

However, if your current theme supports menus, you can add this page to the website menu. But if the template does not support menus, you can go to Appearance > Menus, add the blog page to the menu, and then save it.

Link Mangcoding

B. Using Your Own Page Template for Blog Posts

This method allows you to create a blog section using your own page template. This approach is great when you need to display posts with your own parameters. You can also create multiple blog sections with different queries.

Step 1 – Create a Page Template

Please open your current theme folder and create a PHP file there. You can name it as you wish, for example, blog-template.php. Then, add the following code to this file. :

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

Step 2 – Create a Page

This step is similar to the first step in the first method, the only difference is that you need to specify the page template in the ‘Page Attributes’ section.

blog section mangcoding

Step 3 – Paging Navigation

Of course, we need pagination for our blog section. You may use a plugin or your own function for this purpose. If any issues arise, we recommend using the WP-PageNavi plugin.

Step 4 – Code for the Page Template

This is just an example without some essential template functions like get_header() or get_footer(). However, this template includes 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
?>

That’s the explanation of 2 Ways to Create a Separate Blog Page in WordPress that Mangcoding can share. Hopefully, this article is useful and provides new insights for you. If you have constructive feedback or suggestions, feel free to leave a comment or contact us via email and Mangcoding’s social media.

Source : Rudrastyh.com

Link Copied to Clipboard