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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的