ThemeForest

Wordpress Guru please....

204 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • United States
  • Referred between 50 and 99 users
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.

2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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 :)

2 years ago
204 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • United States
  • Referred between 50 and 99 users
mlando says

I’ll give that a spin… many thanks.

2 years ago
204 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • United States
  • Referred between 50 and 99 users
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+

2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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…

2 years ago
3624 posts
  • Has been a member for 3-4 years
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Interviewed on the Envato Notes blog
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Author had a Free File of the Month
  • Beta Tester
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 50 and 99 items
  • Venezuela
  • Referred between 1 and 9 users
Ivor 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;?>
 
2 years ago
Ivor is a moderator
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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 ?!

2 years ago
204 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • United States
  • Referred between 50 and 99 users
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?

2 years ago
339 posts Don't be a HATER!
  • Has been a member for 2-3 years
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
webinpixels says

Try to reset the loop…

wp_reset_query();

Good luck ;)

2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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.

2 years ago
by
by
by
by
by