【问题标题】:ARCHIVE.PHP SHOWS ONLY ONE POST PER CATEGORYARCHIVE.PHP 每个类别只显示一个帖子
【发布时间】:2017-01-16 16:26:36
【问题描述】:

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

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

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

【问题讨论】:

    标签: php wordpress templates


    【解决方案1】:

    我认为您的 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); ?>
    

    【讨论】:

    • 太好了,现在可以使用了:inunfuturoaprile.it/politica。谢谢!现在,如果我想在有序列表中显示文章怎么办?
    • 您可以将链接包装在 div 中以分隔它们&lt;div&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" .... &lt;/small&gt;&lt;/div&gt;
    • 或者如果你需要在&lt;li&gt;...&lt;/li&gt;和
      打开&lt;ol&gt;标签之后的有序列表包装链接,在循环之前关闭它
    • 我也认为你应该改变这个块中的顺序:&lt;?php endif; ?&gt;&lt;/div&gt;&lt;/div&gt; to '
      '
  • 谢谢格林! ;)
  • 猜你喜欢
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    相关资源
    最近更新 更多