dongmi5015 2017-01-16 16:26
浏览 70
已采纳

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

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 :)

  • 写回答

1条回答 默认 最新

  • dqxsuig64994 2017-01-16 21:20
    关注

    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); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败