Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Calling FoundationPress_pagination in a custom query #229

Closed
magicjoef opened this issue Feb 17, 2015 · 4 comments
Closed

Calling FoundationPress_pagination in a custom query #229

magicjoef opened this issue Feb 17, 2015 · 4 comments

Comments

@magicjoef
Copy link

Hi, is it possible to call the built in pagination function using a custom query (I'm retrieving some custom posts using $loop = new WP_Query( $args ); etc)

Thank you for an excellent starter theme!

@Pautomagi
Copy link

I do it like this:
<?php 
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
     'paged' => $page,
     );
query_posts($args);
?>

Run the loop and use the pagination function.

<?php if ( function_exists('FoundationPress_pagination') ) { FoundationPress_pagination(); } else if ( is_paged() ) { ?>
    <nav id="post-nav">
        <div class="post-previous"><?php next_posts_link( __( '&larr; Older posts', 'FoundationPress' ) ); ?></div>
        <div class="post-next"><?php previous_posts_link( __( 'Newer posts &rarr;', 'FoundationPress' ) ); ?></div>
    </nav>
<?php } ?>

@magicjoef
Copy link
Author

Thanks very much for your reply. I've kept your snippet for future reference, and used part of it to help me find a solution for using wp_query.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'mycustompost', 'posts_per_page' => '5', 'paged' => $paged );
$wp_query = new WP_Query( $args );

Two things tripped me up, seems that using the variable name $wp_query is important, and also if you have a page slug and custom post type called the same thing, you'll get a 404 permalink problem.

Thanks.

@Pautomagi
Copy link

The slug and custom post type is a known wordpress problem. There is a fix for this.
In short: rewrite custom post type slug to a singular name and use plural name for archive/page.

Variable name is not important if you run the loop with the same variable name as specified. If none specified wp_query is default.

query_posts($args) will manipulate the default wordpress query.

@magicjoef
Copy link
Author

I see, that's great, thanks for your help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants