我正试图从主页的第一页中排除前5篇帖子,但我无法做到这一点。这是我想遵循的模式:
第1页:第5后、第6后、第7后、第8后、第9后第2页:第10后、第11后、第12后、第13后、第14后第3页:第15后、第16后等
function my_function_for_excluding_posts( $query ) {
if ($query->is_home() && $query->is_main_query()) {
$query->set( \'offset\', \'5\' );
}
}
add_action( \'pre_get_posts\', \'my_function_for_excluding_posts\' );
这在一定程度上是可行的,因为它排除了前五篇文章,但也在每个页面上重复相同的文章,因此没有遵循我所寻找的模式。这是我的循环文件,它基本上完成了所有的工作,因为我的单曲。php基本上只是调用循环文件来处理所有事情。这是未更改的文件,因为我试图添加new WP_Query
, 但效果不好,所以这里没有编辑:
<?php
global $post, $query_string, $SMTheme;
query_posts($query_string);
$i=1;
if (have_posts()) :
if (!isset($_GET[\'ajaxpage\'])) {?>
<div class=\'articles\'>
<?php }
while (have_posts()) : the_post();
?>
<div class=\'one-post\'>
<div id="post-<?php the_ID(); ?>" <?php post_class("post-caption"); ?>>
<?php if (!is_single()&&!is_page()) { ?>
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( $SMTheme->_( \'permalink\' ), the_title_attribute( \'echo=0\' ) ); ?>" class=\'post_ttl\'><?php the_title(); ?></a></h2>
<?php } else { ?>
<?php if (!is_single()) {?><h1 style="text-align:center;border-bottom:1px solid;margin-top:-10px;max-width: 100%;"><?php the_title(); ?></h1>
<?php } else { ?><h1><?php the_title(); ?></h1>
<?php } ?>
<?php } ?>
<?php if (!is_page()) {?><p class=\'post-meta\'>
<span class=\'post-date\'><span class="day"><?php echo get_the_date(\'d\'); ?></span><br /><span class="month"><?php echo get_the_date(\'M\'); ?></span><br /><span class="year"><?php echo get_the_date(\'Y\'); ?></span></span>
Publicado en <?php the_category(\', \'); ?>
<?php if(comments_open( get_the_ID() )) {
?> | <?php comments_popup_link( 0, 1, \'%\' ); ?> Comentario(s) <?php
}
edit_post_link( $SMTheme->_( \'edit\' ), \' | <span class="edit-link"> \', \'</span>\' );
?>
</p><?php } ?>
<?php
if(has_post_thumbnail()) {
?><?php if (!is_single()) { ?><a href="<?php the_permalink(); ?>" title="<?php printf( $SMTheme->_( \'permalink\' ), the_title_attribute( \'echo=0\' ) ); ?>"><?php the_post_thumbnail(
array($SMTheme->get( \'layout\', \'imgwidth\' ), $SMTheme->get( \'layout\', \'imgheight\' )),
array("class" => $SMTheme->get( \'layout\',\'imgpos\' ) . " featured_image")
); ?></a><?php } else { ?>
<?php the_post_thumbnail(
array($SMTheme->get( \'layout\', \'imgwidth\' ), $SMTheme->get( \'layout\', \'imgheight\' )),
array("class" => $SMTheme->get( \'layout\',\'imgpos\' ) . " featured_image")
); ?>
<?php }
}
?>
</div>
<div class=\'post-body\'>
<?php
if (!is_single()&&!is_page()) {
if ( ! post_password_required() ) { smtheme_excerpt(\'echo=1\'); } else the_content(\'\');
?><a href=\'<?php the_permalink(); ?>\' class=\'readmore\'><?php echo $SMTheme->_( \'readmore\' ); ?></a><?php
} else {
the_content(\'\');
}
?>
<?php if (is_single()) { ?>
<div class="navigation">
<div class="alignleft"> <?php previous_post_link(\'%link\', \'← %title\', true); ?></div>
<div class="alignright"><?php next_post_link(\'%link\', \'%title →\', true); ?></div>
</div>
<?php } ?>
<?php wp_link_pages(); ?>
</div>
</div>
<?php endwhile; ?>
<?php if (!isset($_GET[\'ajaxpage\'])) {?>
</div>
<?php } ?>
<?php endif; ?>
任何帮助或建议都将不胜感激。