Support » Fixing WordPress » Custom query and paging

  • Hi, I have trawled the web and not found a solution to this.

    I have a page called projects and a templated called projects. I have set this page to be my home page.

    I need to show one featured post (from a category) and then rows of 3 other projects (projects is a category).

    How do I have paging so it has

    <div class="row rowOne">
    <ul>
    <?php $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 3, 'cat' => '-10, -72' ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <li>
    <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?> <?php the_title(); ?></a>
    <span><?php the_time('d.m.y') ?></span>
    </li>
    <?php endwhile; ?>
    </ul>
    </div>

    So is it possible to have paging at the bottom of this custom query?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try using:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 3, 'cat' => '-10, -72&paged=' . $paged) ); ?>

    Then use the next/previous template tags as per usual.

    Thread Starter leads

    (@leads)

    Hi. Thanks for that. Tried the next/prev links in various place, but can’t get them to appear on my page

    <?php
    get_header();
    ?>
    <h1 class="hide">Name Creative</h1>
    <div id="featuredProject">
    <?php $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 1, 'cat' => '10' ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail( 'single-post-thumbnail' ); ?></a>
    <ul>
    <li><?php foreach((get_the_category()) as $cat) { if (!($cat->cat_ID=='71' || $cat->cat_ID=='13' || $cat->cat_ID=='10')) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. '' . $cat->cat_name . '</a>';} ?>
    </li>
    <li class="date"><?php the_time('d.m.y') ?></li>
    <li><h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2></li>
    </ul>
    <?php endwhile; ?>
    </div>
    
    <div class="row">
    <ul>
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 3, 'cat' => '-10, -72&paged=' . $paged) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <li>
    <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?> <?php the_title(); ?></a>
    <span><?php the_time('d.m.y') ?></span>
    </li>
    <?php endwhile; ?>
    </ul>
    </div>
    <?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with something like this:

    <div class="navigation">
      <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
      <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    in stead of:

    <?php posts_nav_link(' — ', __('« Previous Page'), __('Next Page »')); ?>
    Thread Starter leads

    (@leads)

    Hi. Thanks but that doesn’t display anything either.

    This is my current setup. It’s a template which has been set as my homepage

    http://code-bin.homedns.org/828

    thanks for your time and input.

    Tom

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom query and paging’ is closed to new replies.