• Hi,

    I have a category template for the shop section of my website (category-shop.php) and i am trying to write a query that will show 30 posts on this page. The problem is on the admin settings page i have it set to show a maximum of 10 posts per page, so i need to override this. I also need to have a link at the bottom which allows users to click to page 2,3,4 etc of the shop as there is likely to be a few hundred products/posts in this category.

    I’ve tried to attempt this all morning and just seem to be getting nowhere. Can anyone please help me.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter paa1605

    (@paa1605)

    Hi,

    Yes i’ve read all those and a few other examples i’ve found online. The theme is one that i’m building myself yet i can’t seem to crack this problem. Some of the examples i’ve tried will pull the correct number of posts from the shop category, but when i click on the link to the second page, it just shows the content from the home page, yet the url is saying mysitedotcom/page2.

    Very frustrating so any help would be much appreciated.

    please post the full code of your category-shop.php template – please use the pastebin https://codex.www.ads-software.com/Forum_Welcome#Posting_Code

    Thread Starter paa1605

    (@paa1605)

    It’s as simple as this right now as just trying to get the code to work before i style it…

    <?php get_header(); ?>
    
    	<div id="white-background">	
    
    		  <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $args = array(
              'cat' => 2,
              'posts_per_page' => 30,
              'paged' => $paged
            );
    
            query_posts($args);
            ?>
    
                        <?php
                       if(have_posts()) :
                          while(have_posts()) :
                             the_post();
                        ?>
    
                                    <h1><?php the_title() ?>
                                    </h1>
    
     																				<?php endwhile; ?>
    
    																						<?php posts_nav_link(); ?>    
    
                                                                                        <?php else: ?>
                                                                                        Sorry, there are currently no articles in this category.
                                                                                         <?php endif; ?>
    
        </div>
    
    <?php get_footer(); ?>

    have a link at the bottom which allows users to click to page 2,3,4 etc

    there should be an answer to that in https://codex.www.ads-software.com/Pagination?

    consider to use next_posts_link() and previous_posts_link() resp; or a plugin like https://www.ads-software.com/plugins/wp-pagenavi/

    btw:
    your template code is not complete; the loop is missing the endwhile; and endif;
    review
    https://codex.www.ads-software.com/The_Loop
    and possibly
    https://codex.www.ads-software.com/Theme_Development

    Thread Starter paa1605

    (@paa1605)

    Thanks for the reply.

    You may have needed to scroll to the right to see it but the code does include a endwhile and endif statement, as well as a link to page 2,3 etc using the posts_nav_link function. From what i read on the codex the next_post_link should be used on the post (single.php) code, and not a category like in this instance.

    Anyway with the current code below it displays the correct number of posts, from the correct category, with a link to page 2. However, page 2 just shows the content from my home page, even though the url is reading mysitedotcom/page2.

    Any help with fixing this is much appreciated.

    <?php get_header(); ?>
    
    	<div id="white-background">	
    
    		  <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $args = array(
              'cat' => 2,
              'posts_per_page' => 30,
              'paged' => $paged
            );
    
            query_posts($args);
            ?>
    
                        <?php
                       if(have_posts()) :
                          while(have_posts()) :
                             the_post();
                        ?>
    
                                    <h1><?php the_title() ?>
                                    </h1>
    
     			<?php endwhile; ?>
    
    					<?php posts_nav_link(); ?>    
    
                               <?php else: ?>
                                Sorry, there are currently no articles in this category.
                               <?php endif; ?>
    
        </div>
    
    <?php get_footer(); ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to over-ride wordpress settings and include pagination.’ is closed to new replies.