WordPress.org

Ready to get started?Download WordPress

Forums

How to show all posts on a custom page, paginated? (4 posts)

  1. Joe
    Member
    Posted 7 years ago #

    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.


    <?php
    /*
    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; ?>

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=2&showposts=5&paged=$page");
    ?>

    <?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;'); ?>

    </div>

    <?php get_footer(); ?>

  2. Rok
    Member
    Posted 7 years ago #

    </div>

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

  3. Dgold
    Member
    Posted 7 years ago #

    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).

  4. Joe
    Member
    Posted 7 years ago #

    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)?

Topic Closed

This topic has been closed to new replies.

About this Topic