• Hi,

    Ive been setting up a few custom page templates so I can display posts from certain categories with my own customisation on page.

    Im a little stuck though because I’ve just realised pagination isn’t working. It reaches the maximum posts and displays the pagination navigation from the loop however click on next or one of the page numbers just reloads the same page.

    Here is a past of the code on my homepage for example.

    http://pastebin.com/BnwNH67G

    Thanks in advance

Viewing 15 replies - 1 through 15 (of 22 total)
  • Thread Starter djdeejay

    (@djdeejay)

    Thanks Esmi,

    Id seen most of those but stumped across this page http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html which seemed to be exactly what I wanted.

    So i replaced the code in the past bin with this.

    <?php query_posts( array( ‘cat’ => 9, ‘posts_per_page’ => 3, ‘paged’ => get_query_var(‘paged’))); ?>

    However I’m left with exactly the same problem, it display the first 3 posts fine and the pagination options appear, but clicking on page two just refreshes the page…

    I tried changing “paged” for “page” – as it is a page template as that website suggests, but in this case it strangely just displays one post only and pagination still doesn’t work.

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( array( 'cat' => 9, 'posts_per_page' => 3, 'paged' => $paged); ?>
    Thread Starter djdeejay

    (@djdeejay)

    No worries, with a little bit of tweaking Ive cracked it. There was some code missing from the top of the page which seems to create the pagination upon page refresh.

    “<?php $save_post = $post;
    $post = get_post( get_option(‘page_for_posts’) ); ?>”

    I changed it back to ‘page’ and it has worked.

    One question though. On my home page I don’t really want pagination anyway – I just want it to display the latest 3 posts dynamically. Is there a setting to turn off and hide the pagination options literally just displaying the three posts in a grid? I can’t see the option anywhere on the links provided to be able to do this…

    Thread Starter djdeejay

    (@djdeejay)

    esmi.

    In my custom loop here is the pagination code at the bottom.

    <?php pagination(); ?>

    Is there a way to modify this so the pagination code is remove if it is the “front page”?

    There’s no pagination() function in WordPress core, so I can only assume that this is coming from your theme or a plugin. Start by finding out which it is.

    try and wrap the code into a conditional statement using is_paged()

    http://codex.wordpress.org/Function_Reference/is_paged

    Thread Starter djdeejay

    (@djdeejay)

    esmi – the pagination() is part of my themes custom loop (loop-grid.php) and it relates to a plugin thats built into the theme (rather than on the plugin page)

    I thought there might be a simple way to wrap pagination() in some php code which tells it not to run if its on the front page…although not sure if the loop sequence would know if it was the front page or not?

    I suppose another way would be to duplicate loop-grid.php and remove the <?php pagination(); ?> bit which works and tell that specific page to use the alternative loop – however I’m stumped as to how to do that easily and quickly either…

    As per alchymyth’s suggestion:

    <?php if(( is_home() || is_front_page() ) && !is_paged() ) pagination(); ?>

    should work.

    Thread Starter djdeejay

    (@djdeejay)

    Argh, I thought that had cracked it.

    It does work in that it removes pagination from the homepage…but only because it removes it from everywhere – as if I’ve just deleted the <?php pagination(); ?> line.

    <?php if(( is_home() || is_front_page() ) && !is_paged() ) echo 'Boo!';?>

    works just fine for me as a test.

    Thread Starter djdeejay

    (@djdeejay)

    Where do I need to put that in relation to <?php pagination(); ?> in the loop esmi?

    Thread Starter djdeejay

    (@djdeejay)

    Ok, I entered this…

    <?php if(( is_home() || is_front_page() ) && !is_paged() ) echo 'Boo!';
    
    		pagination();?>

    But it doesn’t work. Pagination isn’t broken like it was in the first one now, but instead it works everywhere, including on the home page as if it was just the standard <?php pagination(); ?> code.

    Erm – you did realise that the echo "Boo" was purely for my testing, yes? If you want to use it yourself, you need to try:

    <?php if(( is_home() || is_front_page() ) && !is_paged() :
    echo 'Boo!';
    pagination();
    endif;?>
    Thread Starter djdeejay

    (@djdeejay)

    No I wasn’t, I don’t know what the “echo” part it supposed to do in this code…I don’t know PHP only enough to blag my way through…I think you’re assuming a level of knowledge here with short answeres thats probably making it 5x longer to get to the finish.

    What is the ‘echo’ part for? Displaying text somewhere? Where and why…you need to explain to me what this extra part does and why it should work or I’m just stabbing in the dark.

    Im entering this into my loop-grid.php. I’ll reiterate before, will “is_home” commands work from inside the loop?

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Can anyone help me get pagination working correctly in my theme.’ is closed to new replies.