我对 Wordpress 主题开发非常陌生,并且发现自己在编码方面陷入了困境。
我创建了两个循环,其中一个循环只有 1 个帖子,我用更大的图像对其进行样式设置,在第二个循环中,我尝试获取帖子的其余部分,但我遇到了一些主要问题。
在第二个循环中,第一个循环的帖子也出现了,我想避免重复。
当我转到第 2 页或更远时,第一个循环的帖子也出现了,我希望它只出现在根页面上。
下面是我的代码。
第一个循环
<?php
$bigi = array(
'posts_per_page' => '1',
'post__not_in' => get_option( 'sticky_posts' ),
);
$restp = new WP_Query($bigi);
?>
<!-- Loop started for bigimage single post -->
<?php if($restp->have_posts()) { ?>
<?php while($restp->have_posts()) { ?>
<?php $restp->the_post();
$post_id = get_the_ID(); ?>
<?php get_template_part('template/post/bigimage'); ?>
<?php } ?>
<?php } ?> <!-- Loop ended for rest of the post -->
<?php wp_reset_postdata(); ?>
第二循环
<?php
$ropl= new WP_Query(array (
'post__not_in' => get_option('sticky_posts'),
'paged' => $paged,
));
?>
<!-- Loop started for bigimage single post -->
<?php if($ropl->have_posts()) { ?>
<?php while($ropl->have_posts()) { ?>
<?php $ropl->the_post(); ?>
<?php get_template_part('template/post/rop'); ?>
<?php } ?>
<?php } ?> <!-- Loop ended for rest of the post -->
<?php wp_reset_postdata(); ?>