It’s a common question, I used to ask from many WordPress beginners that “how to add post in WordPress page?”. As by default, all the posts get displayed on the dedicated blog page. If someone want to display posts on some other web page, what is the solution?

If you have just started with WordPress, you’ll notice that every blog post you write gets displayed on the front page of your website. But, if you want to show posts on a page other than the home page, you need to know some HTML, PHP, WordPress file structure etc. But don’t panic, it’s easy though. So, here at Templatetoaster WordPress theme builder and WordPress website builder showcases the tutorial that guides you with how to add post in WordPress page.

 

Add Posts to a Page in WordPress

It seems a difficult task that how to add posts to a page in WordPress. Though it has many proposed solutions as follows

  • By creating a custom_template.php
  • By using WP_Query
  • By using Posts in Page plugin

So, let us delve deeper to see each method in detail as follows

 

1. By Creating a Custom Page Template

Create a custom_template.php. in the Theme folder. Assign this to the pages require posts to display. In the custom template, write the following code that will fetch the posts

<?php $args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '', 'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post', 'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true
);

$myposts = get_posts( $args );

foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endforeach;
wp_reset_postdata();
?>

Make a new post category and update the related data in page template accordingly. Now, run the wp_query with desired parameters in the custom template.

Navigate to the page on which you want to add the posts. Look for a big blue “Publish” button, there is a section called “Page Attributes”. One of the page attributes will be “Template”. Change your page template to new custom template and re-publish your page. You are done !!

 

2. By Using WP_Query

Create a snippet for [shortcode] in functions.php and add wp_query loop to it. Then, use this [shortcode] as content in the desired pages using post editor. The wp_query standard loop code will be as follows

<?php

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}

As you want to pick the posts category-wise, you will fire a query related to that. The queries for specific category will be as follows

 

Category Parameters

Display the posts associated with certain categories.

  • cat (int) – use category id.
  • category_name (string) – use category slug.
  • category__and (array) – use category id.
  • category__in (array) – use category id.
  • category__not_in (array) – use category id.

 

Display Posts for One Category

Show posts that have this category (and any children of that category), using category id

$query = new WP_Query( array( 'cat' => 4 ) );

 

Show posts that have this category (and any children of that category), using category slug

$query = new WP_Query( array( 'category_name' => 'staff' ) );

 

Show posts that have this category (not children of that category), using category id

$query = new WP_Query( array( 'category__in' => 4 ) );

 

Display Posts from Several Categories

Show posts that have these categories, using category id

$query = new WP_Query( array( 'cat' => '2,6,17,38' ) );

 

Show posts that have these categories, using category slug

$query = new WP_Query( array( 'category_name' => 'staff,news' ) );

 

Show posts that have “all” of these categories

$query = new WP_Query( array( 'category_name' => 'staff+news' ) );

 

Exclude Posts Belonging to Category

Show all posts except those from a category by prefixing its id with a ‘-‘ (minus) sign

$query = new WP_Query( array( 'cat' => '-12,-34,-56' ) );

 

3. By Using Posts in Page Plugin

WordPress plugin “Posts in Page ” is a more simple answer to the question that how to add Post in WordPress page. It will replace all the coding work and serves the same. You can easily install “Post in Page” from WordPress repository or search from WordPress Dashboard too. The question is how to add Post in WordPress page using this plugin.

Once installed just copy the shortcode of the plugin on the desired page to get posts. It has different shortcodes for different requirements. All the possible shortcodes are given below

 

Shortcodes for the WordPress Editor

  • [ic_add_posts] – To put all the posts to a page, essentially adds to a blog “page”.
  • [ic_add_posts ids=’1,2,3′] – to show one or many posts by specifying the post ID(s).
  • [ic_add_posts post_type=’post_type’] – to show posts from a custom post type by specifying the post type slug. Add multiple post types by separating with commas (e.g.- post_type=’post_type1,post_type2′).
  • [ic_add_posts showposts=’5′] – to limit number of posts (or override default setting).
  • [ic_add_posts orderby=’title’ order=’ASC’] – orderby title – It supports all WP orderby variables. Order is optional, WP default is ‘DESC’.
  • [ic_add_posts category=’category-slug’] – to display posts of a specific category. Uses slugs, can have multiple but separate by commas. Category 1, Category 2, etc.
  • [ic_add_posts exclude_category=’category-slug’] – Exclude posts within specific category. Uses slugs, can have multiple slugs separated by commas. Category-1, Category 2, etc.
  • [ic_add_posts tag=’tag-slug’] – Show posts with a specific tag. As in categories, it uses slugs, and can include multiple tags separate by commas. Tag 1, Tag 2, etc.
  • [ic_add_posts tax=’taxonomy’ term=’term’] – limit posts to those that exist in a taxonomy and have a specific term. Both are required for either one to work.
  • [ic_add_posts template=’template-in-theme-dir.php’] – In case you want to style your markup, add meta data, etc. you will use it. Each shortcode can refer a different template. These templates must be in theme directory.
  • [ic_add_posts ignore_sticky_posts=’no’] – Show sticky posts too.
  • [ic_add_posts paginate=’yes’] – use pagination links (off by default).
  • [ic_add_posts label_next=’Next’ label_previous=’Previous’] – Customize ‘Next’ and ‘Previous’ labels used by pagination.
  • [ic_add_posts post_status=’private’] – to display posts with the specified status. By default, it includes posts with ‘publish’ status only. To select post with multiple status, separate them with commas like: post_status=’private,publish’.

 

Wrapping Up

By default, all the posts in WordPress get published on Blog Post page. But, if a user wants to publish posts on a different page, can easily follow any method as discussed above. All the methods are tried, tested and work well. So, it entirely depends on user choice to go which way. If you want a reliable solution to create outstanding themes, you can use TemplateToaster, a website builder and web design software that is compatible with almost all the WordPress plugins. It provides all the latest features of designing in a single click. So, go for it !!

Hoping this article will be helpful for you. If you have any question, you can share in the comments section !!

Related reading: WordPress 101 tutorial

How to check WordPress version

How to find WordPress login url

How to install WordPress

What WordPress theme is that

How to change WordPress language

How to create WordPress custom login page

How to create WordPress theme from scratch

How to fix WordPress page update not working