marcoloprete
marcoloprete

Reputation: 23

ARCHIVE.PHP SHOWS ONLY ONE POST PER CATEGORY

I realized my website (www.inunfuturoaprile.it) with a minimal Wordpress theme that does not include the category.php template. I have created the template by me: the goal was to get pages that display a list of the posts belonging to a specific category. Unfortunately, due to my scarce knowledge of php, the code does not seem to work properly: I only see one post per category (e.g. https://www.inunfuturoaprile.it/politica/).

Here's the category.php file code:

<?php
/**
* Template di Categoria
*/

get_header(); ?> 

<div id="content">

<?php 
// Check if there are any posts to display
if ( have_posts() ) : ?>

<?php 
// Since this template will only be used for Design category 
// we can add category title and description manually. 
// or even add images or change the layout
?>

<h1><strong><?php single_cat_title(); ?></strong>: Elenco Articoli</h1>

<div class="entry">

<?php
// The Loop
while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> // <small><?php the_time('j F Y') ?></small>
<?php endwhile; // End Loop



else: ?>
        <h2 class="center">Not Found</h2>
        <p class="center">Sorry, but you are looking for something that isn't here.</p>

    <?php endif; ?>
</div>
</div>

<?php get_footer(); ?>

Someone can help me? Thank you :)

Upvotes: 2

Views: 1462

Answers (1)

Grin
Grin

Reputation: 6662

I think your posts_per_page parameter is set to 1.

You can see other posts using pagination:

https://www.inunfuturoaprile.it/politica/page/2/

https://www.inunfuturoaprile.it/politica/page/3/

Check it on Settings->Reading page ( /wp-admin/options-reading.php), parameter "Blog pages show at most"

But it also can be set up somewhere in the theme code.

Changing it may affect your main page - since the main page shows only one post too.

So you can change it only on category.php page. Add this after get_header():

get_header();
global $wp_query;
$wp_query->set('posts_per_page', 10);
// or this - if you need no pagination at all:
// $wp_query->set('nopaging', true);
$wp_query->query($wp_query->query_vars); ?>

Upvotes: 1

Related Questions