206 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
mlando says

Looking for a piece of code that can over-ride the post-per page limit for different category pages while still maintaining pagination. Seems like this would be easy enough butI just can’t seem to get my head around it. query_posts with &showpost won’t do it as it is a category page so pagination breaks.

Anyone? thanks.

2459 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

Not sure I understood if this is what you need, but would this help?

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

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("posts_per_page=2&paged=$paged"); ?>

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

// loop content here

<?php endwhile; endif; ?>

EDIT : of course, you’d change the posts_per_page=2 to your needs :)

206 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
mlando says

I’ll give that a spin… many thanks.

206 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
mlando says

didn’t work :( I think I tried that… I must have overlooked something. It is giving me pagination but the post don’t show on page 2+

2459 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

Yeah, forgot about that…you’ll have to add something extra.

So, I’ve been using it on a client site – it needed to be done fast, so please excuse the barbarian way I chose :D

Add this to the top of your category template (below the header call):


&lt;?php $arc_year = get_the_time('Y');

$arc_month = get_the_time('m');

$arc_day = get_the_time('d'); 

?&gt;

Now it should work.

Then, when you need to create links to the date archive, use something like this:

<a href="<?php echo get_month_link($arc_year, $arc_month); ?>" title="All articles from <?php unset($previousday); printf( __( '%1$s', 'wpbx' ), the_date( 'j F Y', '', '', false ) ) ?>">

<?php unset($previousday); printf( __( '%1$s', 'wpbx' ), the_date( '', '', '', false ) ) ?>

</a>

If you find something lighter/easier, do share :)

Hope it helps…

4338 posts ThemeForest Reviewer
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Member of the Envato Team
+12 more
Ivor Envato team says

This loop will do the trick ;)

<?php $temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query?>query('showposts=5&category_name=thecategoryname'.'&paged='.$paged);
?>
<?php while ($wp_query?>have_posts()) : $wp_query->the_post(); ?>
    <?php the_content(); ?>
<?php endwhile; ?>

<div class="navigation">
  <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
  <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
</div>
<?php $wp_query = null; $wp_query = $temp;?>
 
2459 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

Unfortunately I can’t test Ivor’s code on my client’s site now.

But if mlando confirms everything works fine, including dates & all, Ivor you’re a life saver :D

EDIT : where’s the Subscribe to this thread’s RSS button ?!

206 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
mlando says

@ivor

thanks tried this and similar… doesn’t seem to to work for the category page. It looks good until you click the next page and nothing shows on the next pages??

any other ideas?

448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

Try to reset the loop…

wp_reset_query();

Good luck ;)

2459 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

mlando, did you use the whole code I wrote?

It’s working perfectly fine for me.

Here it is, this time in full, for your reference:

<?php get_header(); ?>

<?php $arc_year = get_the_time('Y');
$arc_month = get_the_time('m');
$arc_day = get_the_time('d'); 

 ?>

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

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("posts_per_page=2&paged=$paged"); ?>

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

<?php the_content(); ?>

Written on <a href="<?php echo get_month_link($arc_year, $arc_month); ?>" title="All articles from <?php unset($previousday); printf( __( '%1$s', 'wpbx' ), the_date( 'j F Y', '', '', false ) ) ?>">

<?php unset($previousday); printf( __( '%1$s', 'wpbx' ), the_date( '', '', '', false ) ) ?>

</a>

<?php endwhile; endif; ?>

<?php get_footer(); ?>

Just saw this: note that Ivor’s code works only for a single (or multiple) designated category/categories. The code I wrote above, although I admit – not very smart, works for all your categories, no need to define which ones.

by
by
by
by
by
by