Answer the question
In order to leave comments, you need to log in
How to create a dynamic display of articles in the appropriate categories in wordpress?
Good afternoon, most likely a banal question, but I stubbornly can not find an answer.
There is a blog, there is a category page template. There are many categories, of course. How to correctly display articles as a list on the category page? We go to category 1 - we see articles of category 1, in category 2 - articles of category 2.
Code for the category page template:
<?php get_header(); ?>
<header class="page-header ">
<div class="page-header__inner">
<h1 class="page-header__title"><?php
printf( __( 'Category: %s', 'twentyten' ), '' . single_cat_title( '', false ) . '' );
?></h1>
<p class="page-header__descr"><?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
get_template_part( 'loop', 'category' );
?></p>
<a class="button" href="">Subscribe to Newsletter</a>
<img class="page-header__image" src="<?php echo bloginfo('template_url'); ?>/assets/images/header-blog-image.svg" alt="illustration for the page header">
</div>
</header>
<div class="container">
<div class="main-content">
</div>
</div>
<?php get_footer(); ?>
Answer the question
In order to leave comments, you need to log in
You had to show the code get_template_part()
and visually this function should be in the .main-content block
<div class="container">
<div class="main-content">
<?php get_template_part( 'loop', 'category' ); ?>
</div>
</div>
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>
<?php the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?>
</header>
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
// Previous/next page navigation.
the_posts_pagination(
array(
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
)
);
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question