我正在尝试创建一个包含三个wp\\u查询的页面。第一个查询提取给定类别的前两篇文章,第二个查询提取同一类别的下三篇文章(偏移量2,单位为$args),下一个查询使用(偏移量5)分页提取其余文章。前两个查询按预期执行,但最后一个查询为我提供了转到第二页的选项,并显示了与第1页相同的结果。
我这样做的原因是,我希望前两篇文章的格式为一种方式,第二个查询和接下来的三篇文章的格式为另一种方式,第三个(带分页)的格式为另一种方式。
我知道有一种方法可以用更少的代码来实现这一点,但我不知道怎么做=(如有任何帮助,将不胜感激。
这是我的代码:
<style>
.category-master-3-tiles {
height: 350px;
background-size: cover;
background-position: center;
}
.byline-category {
display:none;
}
</style>
<?php get_header();
$categoryName = get_field(\'category_name\');
$args = array(
\'post_type\' => \'post\',
\'category_name\' => $categoryName,
\'posts_per_page\' => 2,
\'paged\' => $paged
);
$args2 = array(
\'post_type\' => \'post\',
\'category_name\' => $categoryName,
\'posts_per_page\' => 3,
\'offset\' => 2,
\'paged\' => $paged
);
$args3 = array(
\'post_type\' => \'post\',
\'category_name\' => $categoryName,
\'posts_per_page\' => 5,
\'offset\' => 5,
\'paged\' => $paged
);
?>
<!-----------------------------------------------FIRST ROW OF POSTS-->
<div class="row large-collapse medium-uncollapse" style="max-width:100%; width:100%;" >
<?php $custom_query = new WP_Query($args);
while($custom_query->have_posts()) : $custom_query->the_post(); $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?>
<div class="large-6 medium-6 small-12 columns category-master-3-tiles" style="background-image:url(<?php echo $url;?>);">
<a href="<?php the_permalink(); ?>" style="display:block;"></a> <div style="position:absolute; top:10px; left:10px; color:#fff;"><?php the_title(); ?></div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); wp_reset_query();// reset the query ?>
<!-----------------------------------------------SECOND ROW OF POSTS-->
<div class="row" style="max-width:100%; width:100%;" >
<?php $custom_query2 = new WP_Query($args2);
while($custom_query2->have_posts()) : $custom_query2->the_post(); $url2 = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?>
<div class="large-4 medium-4 small-12 columns category-master-3-tiles" style="background-image:url(<?php echo $url2;?>);">
<a href="<?php the_permalink(); ?>" style="display:block;"></a>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); wp_reset_query();// reset the query ?>
<!-----------------------------------------------BLOG ARCHIVE STYLE-->
<?php
$paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1;
$custom_query3 = new WP_Query( $args3 );
?>
<?php if ( $custom_query3->have_posts() ) : ?>
<div class="row">
<div class="large-8 medium-8 columns">
<!-- the loop -->
<?php while ( $custom_query3->have_posts() ) : $custom_query3->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(\'\'); ?> role="article">
<header class="article-header">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</h2>
<?php get_template_part( \'parts/content\', \'byline\' ); ?>
</header> <!-- end article header -->
<section class="entry-content" itemprop="articleBody">
<?php the_excerpt(\'<button class="tiny">Read more...</button>\'); ?>
</section> <!-- end article section -->
<footer class="article-footer">
<?php /*?><p class="tags"><?php the_tags(\'<span class="tags-title">\' . __(\'Tags:\', \'jointstheme\') . \'</span> \', \', \', \'\'); ?></p><?php */?>
</footer> <!-- end article footer -->
</article> <!-- end article -->
<?php endwhile; ?>
</div>
<div class="large-4 medium-4 columns">
<?php include(\'sidebar-category-pages.php\'); ?>
</div>
<!-- end of the loop -->
</div>
<!-- pagination here -->
<?php
if (function_exists(custom_pagination)) {
custom_pagination($custom_query3->max_num_pages,"",$paged);
}
?>
<?php wp_reset_postdata(); wp_reset_query();?>
<?php else: ?>
<p>
<?php _e( \'Sorry, no posts matched your criteria.\' ); ?>
</p>
<?php endif; ?>
<?php get_footer(); ?>