0

I have posts with a certain category(Blog Posts) and I would like to add these to a certain page(Blog). What can I do to add my category to a certain page?

I really appreciate your help!

| improve this question | | | | |
1

Create a page template and use wp_query to target the category you want to display

$args = array('category_name' => 'your category name',);

WP_Query will help you with all sorts of options for what posts are returned and get displayed by your loop.

Here is an example of a page template, (this is based on the _s theme)

<?php
/**
 * Template Name: Your template name
 *
 * @package _s
 */

get_header(); ?>

<section id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

    <?php if ( have_posts() ) : ?>

        <header class="entry-header">
            <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
            <div class="entry-meta">
            </div><!-- .entry-meta -->
        </header><!-- .page-header -->

        <?php 
         $args = array(
         'category_name' => 'your category name',        
         );             
        ?>

        <?php
         $the_query = new WP_Query($args); 
         while($the_query->have_posts()) : $the_query->the_post(); 
        ?>

            <?php
                /* Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that    will be used instead.
                 */
                get_template_part( 'content', get_post_format() );
            ?>

        <?php endwhile; ?>

    <?php else : ?>

        <?php get_template_part( 'content', 'none' ); ?>

    <?php endif; ?>

    </main><!-- #main -->
</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

You can also generate your wp_query making things a bit easier.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.