档案.PHP 每个类别只显示一个帖子



我意识到我的网站(www.inunfuturoaprile.it)有一个最小的Wordpress主题,不包括类别.php模板。我自己创建了模板:目标是获取显示属于特定类别的帖子列表的页面。不幸的是,由于我对 php 的了解稀少,代码似乎无法正常工作:我每个类别只看到一个帖子(例如 https://www.inunfuturoaprile.it/politica/)。

以下是类别.php文件代码:

<?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(); ?>

有人可以帮助我吗?谢谢:)

我认为您的posts_per_page参数设置为 1。

您可以使用分页查看其他帖子:

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

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

在设置->阅读页面(/wp-admin/options-reading.php),参数"Blog pages show at most"上检查它

但它也可以在主题代码中的某个位置设置。

更改它可能会影响您的主页 - 因为主页也只显示一个帖子。

因此,您只能在category.php page上更改它。在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); ?>

最新更新