• I am customizing the archive.php to display a large version of the first post, then list the rest of the posts in boxes. It’s working great, except the offset for the second get_posts() is not working. It is including the first post, and I can’t figure out why; I’ve never had this happen before. Here is the code for my archive.php:

    
    <?php
    /**
     * The template for displaying archive pages.
     *
     * @link https://codex.ww.wp.xz.cn/Template_Hierarchy
     *
     * @package The_Acorn_House
     */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    			<div class="container">
    				<div class="container-inner">
    					
    						
    						<?php 
    						$metaValue = wp_get_terms_meta($cat, 'category_image' ,true); 
    						if ($metaValue){
    							echo '<div class="featured-image"><img src="';
    							echo $metaValue;
    							echo '" /></div><!-- .featured-image -->';
    						}?>
    						
    						
    						<div class="item-box title-box category-title">
    							<div class="item-box-inner">
    								<h2>Category</h2>
    								<?php if (category_description())
    								{
    									echo category_description();
    								} else {
    									echo '<h3>';
    									single_cat_title();
    									echo '</h3>';
    								}
    								?>
    							</div><!-- .item-box-inner -->
    						</div><!-- .item-box -->
    				</div><!--.container-inner -->
    			</div><!--.container -->
    			
    			
    			<?php   // show 3 posts from each subcategory
    				 
    				$categories = get_categories( array(
    				    'orderby' => 'name',
    				    'parent'  => $cat
    				) );
    				
    				if ($categories){
    				
    				foreach ( $categories as $category ) {?>
    				
    				    <div class="container alternaterow blog-subcategory">
    						<div class="container-inner">
    							<?php 
    								echo '<h3><a href="';
    								echo $category->slug;
    								echo '">';
    								echo $category->name;
    								echo '</a></h3>'; ?>
    							
    							<div class="thirdcol-container">	
    								<?php $args = array(
    									'posts_per_page'   => 3,
    									'category'         => $category->term_id,
    									'orderby'          => 'post_date',
    									'order'            => 'DESC',
    									'post_type'        => 'post',
    									'post_status'      => 'publish'
    									 );
    								
    								$myposts = get_posts( $args );
    								foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    									<div class="thirdcol">
    										<div class="blog-excerpt blog-small item-box">
    											<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium-landscape'); ?></a>
    											<?php include(STYLESHEETPATH . '/inc/item-box-inner.php'); ?>
    										</div><!-- .blog-excerpt -->
    									</div><!-- .thirdcol -->
    								<?php endforeach; 
    								wp_reset_postdata();?>
    							</div><!-- .thirdcol-container -->
    						</div><!--.container-inner -->
    					</div><!--.container -->
    
    				<?php }
    				} ?>
    						
    						<!-- show first post, larger -->
    						<div class="container-inner cat-top-post">
    							<?php $args = array(
    								'posts_per_page'   => 1,
    								'category'         => $cat,
    								'orderby'          => 'post_date',
    								'order'            => 'DESC',
    								'post_type'        => 'post',
    								'post_status'      => 'publish'
    								 );
    							
    							$myposts = get_posts( $args );
    							foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    								<div class="featured-image column">
    									<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
    								</div><!-- .featured-image -->
    								
    								<div class="blog-excerpt item-box column">
    									<?php include(STYLESHEETPATH . '/inc/item-box-inner.php'); ?>
    								</div><!-- .blog-excerpt -->
    								
    							<?php endforeach; 
    							wp_reset_postdata();?>	
    								
    						</div><!-- .container-inner -->
    						
    					<div class="container category-list-posts">
    						<div class="container-inner">
    							<div class="thirdcol-container">
    						<?php $args = array(
    								'posts_per_page'   => -1,
    								'offset'           => 1,
    								'category'         => $cat,
    								'orderby'          => 'post_date',
    								'order'            => 'DESC',
    								'post_type'        => 'post',
    								'post_status'      => 'publish'
    								 );
    							
    							$myposts = get_posts( $args );
    							foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    							<!-- show all the rest of the posts, smaller -->
    							
    							<div class="thirdcol">
    								<div class="blog-excerpt blog-small item-box">
    									<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium-landscape'); ?></a>
    									<?php include(STYLESHEETPATH . '/inc/item-box-inner.php'); ?>
    								</div><!-- .blog-excerpt -->
    							</div><!-- .thirdcol -->
    											
    							<?php endforeach; 
    							wp_reset_postdata();
    				
    							//the_posts_navigation();
    				
    						?>
    							</div><!-- .thirdcol-container -->
    						</div><!--.container-inner -->
    					</div><!--.container -->
    					
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php
    get_footer();
    ?>
    
    • This topic was modified 9 years, 1 month ago by mike62.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_posts offset not working’ is closed to new replies.