Answer the question
In order to leave comments, you need to log in
Navigation not working on category.php page?
Good afternoon. Problem with pagination and looping on category page. There are several categories on the site, certain posts belong to them (of course there is nothing informative here, but I will write anyway) I
created a category.php file to display all posts (announcements) in a cycle. In the reading settings, the number of posts is 1, you need to display the last post on the main page.
category.php content
<?php
/**
* Template for displaying Category Archive pages
*
*/
get_header(); ?>
<section id="primary" class="main__content">
<div id="content " role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'ocean' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) ) {
/**
* Filter the default Twenty Eleven category description.
*
* @since Twenty Eleven 1.0
*
* @param string The default category description HTML.
*/
echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_description . '</div>' );
}
?>
</header>
<?php $args = array(
'cat' => $category->term_id,
'post_type' => 'post',
'posts_per_page' => '10',
'prev_text' => __( 'Старые записи' ),
'next_text' => __( 'Новые записи' ),
); ?>
<?php
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<section class="<?php echo $category->name; ?> listing">
<h2>Latest in <?php echo $category->name; ?>:</h2>
<?php while ( $query->have_posts() ) {
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'category-listing' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>
<?php } ?>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt( __( 'Continue Reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); ?>
</article>
<?php } // end while ?>
</section>
<?php } // end if
// Use reset to restore original query.
wp_reset_postdata(); ?>
<?php the_posts_navigation( array(
'prev_text' => 'Предыдущие записи',
'next_text' => 'Следующие записи',
'screen_reader_text' => 'Навигация',
) ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'ocean' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'ocean' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<div class="clearfix"></div>
<?php get_footer(); ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question