WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Standard format category/page navigation issues (3 posts)

  1. stevenknight
    Member
    Posted 1 year ago #

    Hello, I recently added the ability for custom post formats (image, quote, video and aside) for my WordPress theme. It's good but my homepage is getting cluttered with the standard format posts getting lost in the wild.

    So I thought it would be a good idea to have a standard format only page. I created a page template with the following code:

    <?php /* Template name: standard */
    	$args = array( 'showposts' => $number, 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-video','post-format-quote','post-format-image','post-format-aside'), 'operator' => 'NOT IN' ) ) ); query_posts( $args );
    	get_header()
    ?>
    			<div id="posts" class="home">
    				<?php if ( have_posts() ) : ?>
    					<?php ?>
    					<?php while ( have_posts() ) : the_post(); ?>
    						<?php get_template_part( 'content', get_post_format() ); ?>
    				         <?php endwhile; ?>
    				<?php else : ?>
    				<?php endif; ?>
    				<nav class="pagination">
    					<ul>
    						<li class="prev"><?php next_posts_link('« Previous Page') ?></li>
    						<li class="next"><?php previous_posts_link(' :: Next Page »') ?></li>
    					</ul>
    				</nav>
    			</div>
    <?php get_footer(); ?>

    As you can see, the main bit is the first block of PHP code which I found after some Googling. It works and the page only shows standard format posts, however navigation does not work. If I click on "previous" or "next" it just loads up the first page again and I cannot work it out.

    I assume this is because by their definition, pages aren't set up to handle navigation -- but as far as I'm aware there's no way to create custom indexes.

    (Does WordPress have a built in way to only show certain post formats such as blog.com/format/aside because if it does, I cannot find it.)

    Any help would be brilliant, thank you a lot.

    Steven.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    <?php /* Template name: standard */
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    		'posts_per_page' => $number,
    		'paged' => $paged,
    		'tax_query' => array( array(
    			'taxonomy' => 'post_format',
    			'field' => 'slug',
    			'terms' => array('post-format-video','post-format-quote','post-format-image','post-format-aside'),
    			'operator' => 'NOT IN' ) ) );
    query_posts( $args );
  3. stevenknight
    Member
    Posted 1 year ago #

    Thank you, that worked great.

    Now to get ajax 'Load more posts' to work with queries!

    Marked as resolved...

Topic Closed

This topic has been closed to new replies.

About this Topic