我已经完成了一个自定义的wordpress主题,但现在找不到原来的人了。
所有类别都显示在所有类别页面上,尽管我已经创建了一个新的类别并在其中移动了2个帖子。(只是试图创建一个档案)
你们中有谁能帮我指出我需要在category.php页面上寻找的方向吗?(见下文)
<?php if ( is_day() ) : ?>
<h1 class="page-title"><?php printf( __( 'Daily Archives: <span>%s</span>', 'your-theme' ), get_the_time(get_option('date_format')) ) ?></h1>
<?php elseif ( is_month() ) : ?>
<h1 class="page-title"><?php printf( __( 'Monthly Archives:<span>
<?php $archive_query = new WP_Query('showposts=1000');
while ($archive_query->have_posts()) : $archive_query->the_post(); ?>
<div class="row">
<div class="span3">
<?php the_post_thumbnail('full');?>
</div>
<div class="span5">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="entry-summary">
<?php the_content( __( 'Continue reading <span class="meta-nav">
</div><!-- .entry-summary -->
</div><!-- #post-<?php the_ID(); ?> -->
</div>
</div>
<?php endwhile; ?>
我不得不删除一些代码,因为它不让我通过它,这并没有让我充满信心tbh。
我不是Wordpress爱好者,但我知道的基本知识
提前感谢
您永远不应该用自定义查询来替换存档页面或主页上的主查询,您总是会遇到一些问题,就像您现在遇到的那样:-)
要纠正您的问题,请删除此部件
<?php
$archive_query = new WP_Query('showposts=1000');
while ($archive_query->have_posts()) :
$archive_query->the_post(); ?>
并将其替换为
<?php
while(have_posts()) :
the_post();
你现在应该看到正确的帖子出现在
如果您需要更改主查询中的某些内容,请使用pre_get_posts
进行更改。让我们以您的示例代码为例。您需要在所有存档页面上将posts_per_page
更改为1000,然后您可以在functions.php
中执行以下操作
add_action('pre_get_posts', function ($q) {
if (!is_admin() && $q->is_main_query() && $q->is_archive()) {
$q->set('posts_per_page', 1000);
}
});
只要确保,上面的代码需要php5.3+