• Jake

    (@harpomarx-1)


    Hi,

    I want to create a custom category page for a site. On category pages (category.php), the last 3 posts are displayed at the top with a picture, and then a certain number of posts (let’s say 10, so posts 4 to 13) are displayed in a regular list underneath.

    This works well for the first page, see here: http://www.votretorchon.com/motest/category/sports/

    However since I’m using query_posts to retrieve posts, navigation is not working. On page 2 of the category page, I should see the next 10 posts (posts 14 to 23), without the featured posts at the top (I will eventually use an if statement to show or hide this).

    How can I make sure navigation is still working for this type of page?

    Here’s the code I have at this time:

    <?php get_header(); ?>
    
    <div id="contenu02">
    <div class="colonne01">
      <h1 class="pagetitle"><?printf( __('%s','branfordmagazine'), single_cat_title('', false)); ?></h1>
    
       <!--ARTCLES RECENTS -->
        <div class="boite02">
       <?php
       $thequery= "category_name=".single_cat_title('', false)."&caller_get_posts=1&showposts=3&orderby=date";
       query_posts($thequery); ?>
        <?php is_tag(); ?>
        <?php if (have_posts()) : ?>
        <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
        <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="bloc_b">
        <?php // here the thumbnail image gets automatically generated fron the posts own image gallery ?>
          <span class="img_post"><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>"><?php postimage(200,150); ?></a></span>
          <div class="bloc_b_texte">
          <a href="<?php the_permalink() ?>" rel="bookmark">
            <h4><?php the_title(); ?></h4>
          </a>
          <span class="auteur">par: <?php the_author_posts_link(); ?></span>
          <?php the_excerpt() ; ?>
            <?php // the_content_rss('Plus...', TRUE, '', 30); ?>
          </div>
        </div>
        <?php $ids[]= $post->ID;
        endwhile; ?>
        <?php endif; ?>
        <div class="clear"></div>
    </div>
    
        <div class="navigation">
        <div class="alignleft">
          <?php next_posts_link(__('Articles pr&eacute;c&eacute;dents','branfordmagazine')) ?>
        </div>
        <div class="alignright">
          <?php previous_posts_link(__('Articles suivants','branfordmagazine')) ?>
        </div>
      </div>
       <?php
       $thequery= "category_name=".single_cat_title('', false)."&offset=3&orderby=date";
       query_posts($thequery); ?>
      <?php while (have_posts()) : the_post(); ?>
      <div class="post">
        <h4 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php __('Lien permanent vers','branfordmagazine');?> <?php the_title(); ?>">
          <?php the_title(); ?>
          </a></h4>
        <small>
        <?php the_time(__('j F Y','branfordmagazine')); ?>
        |
        <?php _e('Par','branfordmagazine');?>
        <?php the_author_posts_link('namefl'); ?>
        |
        <?php _e('Cat&eacute;gorie:','branfordmagazine');?>
        <?php the_category(', ') ?>
        <?php edit_post_link('Edit', ' | ', ''); ?>
        </small>
        <div class="entry">
          <?php the_excerpt() ?><span class="read_more"><a href="<?php the_permalink(); ?>">[...]</a></span>
        </div>
        <p class="postmetadata">
          <?php if ( function_exists('the_tags') ) {
    			the_tags('<span class="tags"><strong>Tags:</strong> ', ', ', '</span>'); } ?>
          <?php _e('Paru dans','branfordmagazine');?>
          <?php the_category(', '); ?>
          |
          <?php comments_popup_link(__ ('Pas de commentaires »', 'branfordmagazine'), __ ('1 Commentaire »', 'branfordmagazine'), __ngettext ('% commentaires', '% commentaires', get_comments_number (),'branfordmagazine')); ?>
        </p>
      </div>
      <?php endwhile; ?>
      <div class="navigation">
        <div class="alignleft">
          <?php next_posts_link(__('Articles pr&eacute;c&eacute;dents','branfordmagazine')) ?>
        </div>
        <div class="alignright">
          <?php previous_posts_link(__('Articles suivants','branfordmagazine')) ?>
        </div>
      </div>
      <?php else : ?>
      <h2 class="center">
        <?php __('Introuvable','branfordmagazine') ?>
      </h2>
      <?php include (TEMPLATEPATH . '/searchform.php'); ?>
      <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
  • Try:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $thequery= "category_name=".single_cat_title('', false)."&caller_get_posts=1&showposts=3&orderby=date&paged=" . $paged;

    And next time you want to post a large block of code, or a complete template, you might want to use the WordPress pastebin and post the pastebin url here. It makes life easier for everyone.

Viewing 1 replies (of 1 total)

The topic ‘Custom category page template and navigation’ is closed to new replies.