WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Create an archive for gallery format posts (2 posts)

  1. aunrea
    Member
    Posted 1 year ago #

    I am trying to make a page for gallery format posts but have it grouped by year so that you only view the posts with the gallery format for a certain year. So far I have all the posts on one page but there is a lot. I also couldn't get paging to work so I gave up on that but would prefer to have it as that is a lot of posts on one page.

    The code I am currently using (without years or paging) is...

    <ul id="gallery-list">
    	<?php
    	$args = array(
        	'tax_query' => array(
            	array(
              		'taxonomy' => 'post_format',
             		'field'    => 'slug',
              		'terms'    => array( 'post-format-gallery' ),
              		'operator' => 'IN',
           		)
        	),
    		'posts_per_page' => 10000
    	);
    	$gallery = new WP_Query( $args );
    	if($gallery->have_posts()): while($gallery->have_posts()): $gallery->the_post();?>
    		<li class="format-gallery">
               	<?php $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    			if ( $images ) :
    				$total_images = count( $images );
    				$image = array_shift( $images ); ?>
                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?>
                        <h3><?php the_title(); ?></h3>
                    </a>
    				<?php printf( _n( ' (%1$s photos)', ' (%1$s photos)', $total_images, 'simple' ), number_format_i18n( $total_images )	); ?>
                 <?php endif; ?>
    		</li>
    	<?php endwhile; endif; ?>
    </ul>

    An example of what I have got can be viewed at themes.candaceduffyjones.com/type/gallery/?theme=Simple. That is just my test site since the website I am working on is a members only website, but the test site will work fine it just has less galleries.

  2. aunrea
    Member
    Posted 1 year ago #

    Okay I added paging but when I go to page 2 it shows all the posts from page 1 only. What am I doing wrong?

    <?php get_header(); ?>
                	<div id="primary" class="site-content">
    					<div id="content" role="main">
                       		<ul id="gallery-list">
                            	<?php
    							$args = array(
        							'tax_query' => array(
            							array(
              								'taxonomy' => 'post_format',
             							 	'field'    => 'slug',
              								'terms'    => array( 'post-format-gallery' ),
              								'operator' => 'IN',
           								)
        							),
    								'posts_per_page' => 12
    							);
    							$gallery = new WP_Query( $args ); ?>
    							<?php if($gallery->have_posts()): while($gallery->have_posts()): $gallery->the_post();?>
    								<li class="format-gallery">
                                    	<?php
    										$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    										if ( $images ) :
    											$total_images = count( $images );
    											$image = array_shift( $images );
    									?>
                                    		<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?>
                                        	<h3><?php the_title(); ?></h3></a><?php printf( _n( ' (%1$s photos)', ' (%1$s photos)', $total_images, 'simple' ), number_format_i18n( $total_images )	); ?>
                                        <?php endif; ?>
    								</li>
    							<?php endwhile; endif; ?>
                            </ul><!-- #post -->
                            <?php simple_content_nav( 'nav-below' ); ?>
    					</div><!-- #content -->
    				</div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic