Support » Fixing WordPress » Paging Custom Page Template

  • I have a custom page which pulls only a single category of posts, I now have enough postings on that page that the previous and next entries links appear at the bottom of the page, however when you follow these links you get the same postings, here is the original page followed by some changes I tried to implement.

    original code
    <?php
    /*
    Template Name: Events
    */
    ?>

    <?php get_header(); ?>

    <div id=”content” class=”narrowcolumn”>
    <?php
    query_posts(‘page_id=’.$_GET[‘page_id’]);
    $more = 0;
    ?>

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class=”post”>
    <h2 id=”post-<?php the_ID(); ?>”>” rel=”bookmark” title=”Permanent link to <?php the_title();?>”><?php the_title(); ?></h2>
    <div class=”entry”>
    <?php the_content(‘Read more »’); ?>
    </div>
    <p class=”postmetadata”>
    <?php edit_post_link(‘Edit’,”,’ | ‘); ?>
    <?php
    //comments_popup_link(‘ Leave A Comment »’, ‘1 Comment »’, ‘% Comments »’);
    ?>
    </p>
    <?php trackback_rdf(); ?>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>

    <?php
    $query= ‘cat=11’; // concatenate the query
    query_posts($query); // run the query
    $more = 0;
    ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php require(‘post.php’); ?>
    <?php endwhile; ?>

    <div class=”navigation”>
    <div class=”alignleft”><?php posts_nav_link(”,”,’« Previous Entries’) ?></div>
    <div class=”alignright”><?php posts_nav_link(”,’Next Entries »’,”) ?></div>
    </div>

    <?php else : ?>

    <h2 class=”center”>Not Found</h2>
    <p class=”center”><?php _e(“Sorry, but you are looking for something that isn’t here.”); ?></p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>

    <?php endif; ?>

    </div>

    <div id=”sidebar” style=”vertical-align:top;”>

    <div id=”pages_nav”>
    <div style=”margin-left:25px;”>
    <?php if(function_exists(“wp_pages_nav”)) {
    wp_pages_nav(“current=69&sort_column=menu_order&show_parents=0&show_children=1&depth=2”);
    } ?>
    </div>

    <div id=”divArchives”>
    <h3>Archives</h3>
    <?php wp_get_archives(‘type=monthly&limit=12’); ?>
    <?php //get_calendar(); ?>
    </div>

    </div>

    </div>

    <?php get_footer(); ?>

    changes….

    query_posts($query_string);
    $more = 0;

    and

    $query= ‘page_id=’.$_GET[‘page_id’];
    if($_GET[‘paged’] != ”){
    $query=$query . ‘&paged=’ . $_GET[‘paged’];
    }
    query_posts($query);
    $more = 0;

    code changes did not alter the output

Viewing 2 replies - 1 through 2 (of 2 total)
  • Using a pastebin for long pieces of code makes them much easier to read.

    One thought. Is this really the best way to do what you want to do? Why not just use the /category/cat_name URL instead of a special page? You could even use a category template. This would solve your pagination problem, and it would be a more “wordpressy” way to display posts within a category.

    an example

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $postsperpage = 30;
    $offset = ($paged-1) * $postsperpage
    $pageposts = $wpdb->get_results("SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE ... blah ...
    LIMIT $offset, $posts_per_page ", OBJECT);
    ...
    foreach ($posts as $post) :
    setup_postdata($post); ?>
        (loop stuff)
    <?php endforeach; ?>

    works well in my site

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Paging Custom Page Template’ is closed to new replies.