WordPress.org

Forums

Listing custom post types in a page template - pagination returns 404? (3 posts)

  1. pezholio
    Member
    Posted 4 years ago #

    Hi,

    I'm trying list of all posts of a particular type on a page template, and it works great, however, when I click for older posts (http://staffordshirehoard.org.uk.testing.lichfield.vm.bytemark.co.uk/news/page/2) I get a 404. Any ideas where I'm going wrong? Here's the main bit of my code:

    <h2 class="entry-title"><span>News</span></h2>
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=news&showposts=5&paged=' . $paged);
    while ( $wp_query->have_posts() ) : $wp_query->the_post();
    ?>
    
    <article>
    <h3><a href="<?php echo $wp_query->post->guid; ?>"><span><?php echo $wp_query->post->post_title; ?></span></a></h3>
    <p class="date"><?php echo date("l, jS F Y", strtotime($wp_query->post->post_date)); ?></p>
    <p><?php wpe_excerpt('long_excerpt'); ?></p>
    </article>
    
    <?php
    endwhile;
    ?>
    
    <?php if (  $wp_query->max_num_pages > 1 ) : ?>
    	<div id="nav-below" class="navigation">
    		<div class="nav-previous"><?php previous_posts_link('« Previous Entries') ?></div>
    		<div class="nav-next"><?php next_posts_link('Next Entries »','') ?></div>
    	</div><!-- #nav-below -->
    <?php endif; ?>
  2. Marko Jakic
    Member
    Posted 4 years ago #

    This is what I'm searching solution for..

    I think you can't have post type called 'news' and page name is also 'news' - then pagination won't work. It's something about url rewrite, so WP can't differentiate those two.

    So, either call that post type like 'news-post' and page 'news' or page 'news-page' and post leave 'news'

    This problem bothers me for a while now..

  3. landoria
    Member
    Posted 4 years ago #

    Yeah, changing the page slug to something different that the custom page type slug made the pagination stop giving 404.

Topic Closed

This topic has been closed to new replies.

About this Topic