Support » Fixing WordPress » How to show all posts on a custom page, paginated?

  • I have created a page called “News Articles” that uses a template called “news-articles.php”. In that template file I have the code shown below. going to /news-articles/ loads the page, displays the pages content, then shows 5 posts from category 2 and a next page link (as it should). The problem arises when I try to see the next page of posts, I get a 404. It goes to /news-articles/page/2/. I am using home.php to allow static content on the index page if that makes a difference.

    I have been messing with this for over a day now with no luck. I have searched all over, tried 20 different ideas, etc. Am I missing something simple? Is this possible to achive? My end goal is to have all “news articles” show up on the /news-articles/ page, displayed 5 at a time, for as many pages as needed until there are no more news articles.

    Thanks in adanvance for any help. It is greatly appreciated.

    Template Name: News Articles

    <?php get_header(); ?>

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <hr size="1">

    <?php endwhile; ?>
    <?php else : ?>

    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>

    <?php endif; ?>

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

    <?php while (have_posts()) : the_post(); ?>

    <h2><?php the_title(); ?></h2>
    <ul><?php the_excerpt(); ?></ul>

    <?php endwhile; ?>

    <?php posts_nav_link(' - ','Newer Articles &laquo;','Older Articles &raquo;'); ?>


    <?php get_footer(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • </div>

    where is its parent opening <div>????

    A much simpler way to do this:

    Duplicate the file category.php
    Save as category-2.php
    Now modify category-2.php to show your static content at the top.

    As a Category archive, wordpress will automatically handle putting the # of posts per page you want (5), and will automatically handle paginating (next page, previous page).

    The opening <div> is in the header file, I just forgot to remove that closing </div> and put it in the footer file. I don’t think that really has anything to do with why this wont work though…

    Dgold, I tried the category-2.php method as well, and it would work, kind of… basically the next & previous links would go to /news-articles/page/2, which wouldn’t work… however, if I manually entered in the url to /news_articles/?paged=2 then it would work.

    Any other ideas? Or ideas on why the url isn’t being formated properly (or handled properly by the rewriter)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to show all posts on a custom page, paginated?’ is closed to new replies.