Display Posts From Specific Category On A WordPress Page

Today, We want to share with you wordpress display posts from specific category on page.In this post we will show you how to display all posts from a category wordpress, hear for display category on page – wordpress we will give you demo and example for implement.In this post, we will learn about wordpress Get All Parent Categories from Child Categories with an example.

wordpress display posts from specific category on page

There are the Following The simple About display category wise post in wordpress Full Information With Example and source code.

As I will cover this Post with live Working example to develop wordpress only show posts from specific category, so the wordpress display posts from specific category on page plugin is used for this example is following below.

Read Also:  Wordpress woocommerce get product tags

Display content from a specific category

list of posts under the ‘WordPress’ category.

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'category_name' => 'wordpress',
    'posts_per_page' => 5,
);
$arr_posts = new WP_Query( $args );
 
if ( $arr_posts->have_posts() ) :
 
    while ( $arr_posts->have_posts() ) :
        $arr_posts->the_post();
        ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <?php
            if ( has_post_thumbnail() ) :
                the_post_thumbnail();
            endif;
            ?>
            <header class="entry-header">
                <h1 class="entry-title"><?php the_title(); ?></h1>
            </header>
            <div class="entry-content">
                <?php the_excerpt(); ?>
                <a href="<?php the_permalink(); ?>">Read More</a>
            </div>
        </article>
        <?php
    endwhile;
endif;

here simple use the key as ‘cat’ in place of custom ‘category_name’ as well as here pass the id of a category

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'cat' => '4', // 2,3,4,5,6,8,9,15 or more you can pass comma-separated ids here
    'posts_per_page' => 5,
);

Get Posts Under Custom Taxonomy

$args = array(
    'post_type' => 'CUSTOM_POST_TYPE_NAME',
    'post_status' => 'publish',
    'posts_per_page' => 5,
    'tax_query' => array(
        array(
            'taxonomy' => 'TAXONOMY_NAME',
            'field'    => 'slug',
            'terms'    => array( 'TERM_SLUG' ),
            'operator' => 'IN'
        ),
    ),
);
 
$arr_posts = new WP_Query( $args );

using Pagination

get the value for paged

$paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' ) : 1;

template-category.php

<?php
/**
 * Template Name: Category Custom Page
 */
 
get_header(); ?>
 
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
 
    <?php
    $paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' ) : 1;
    $args = array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'category_name' => 'wordpress',
        'posts_per_page' => 5,
        'paged' => $paged,
    );
    $arr_posts = new WP_Query( $args );
 
    if ( $arr_posts->have_posts() ) :
 
        while ( $arr_posts->have_posts() ) :
            $arr_posts->the_post();
            ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <?php
                if ( has_post_thumbnail() ) :
                    the_post_thumbnail();
                endif;
                ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php the_title(); ?></h1>
                </header>
                <div class="entry-content">
                    <?php the_excerpt(); ?>
                    <a href="<?php the_permalink(); ?>">Read More</a>
                </div>
            </article>
            <?php
        endwhile;
        wp_pagenavi(
            array(
                'query' => $arr_posts,
            )
        );
    endif;
    ?>
 
    </main>
</div>
 
<?php get_footer(); ?>

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Read Also:  How to Create a Wordpress Plugin in 10 Minutes Flat

I hope you get an idea about wordpress display posts from specific category on page.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  How to Get current User details in Wordpress woocommerce? | WP_User() | wp_get_current_user() | get_user_by() | get_userdata()
  2. Read Also:  Increase WordPress Memory Limit using PHP
  3. Read Also:  PHP wc_get_product Examples
  4. Read Also:  how to check a plugin is activated or not in wordpress
  5. Read Also:  WordPress Plugin Activation Dependency Check
  6. Read Also:  WooCommerce Get Product Tax, Shipping & Stock
  7. Read Also:  wordpress Get Subcategories List custom PHP pages
  8. Read Also:  WooCommerce Get Product Prices
  9. Read Also:  wordpress Download - free - latest version
  10. Read Also:  WooCommerce Get Product Prices
CLOSEX