SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WP How-to: 10 posts per page with page navigation on custome template... I'm stuck.

    I'm stuck please help.. I can't figure out how-to get page navigation, 10 posts per page.. Is it screwy b/c I'm only showing posts for one category? On another template I'm having the same exact problem except it's showing all categories EXCEPT for one (CAT ID=3 //CAT ID=-3)... If someone could help me out that would be great and much much MUCH appreciated. Here's what the page looks like:

    PHP Code:
    <?php
    /*
    Template Name: Memorials
    */
    ?>
    <?php get_header
    (); ?>
    <?php 
    if (have_posts()) : ?>

    <div id="content">
        <!--page.php-->
    <div id="post" class="post clearfix">
    <div id="blog-heading"><h1>Memorials for Loved Ones Lost</h1></div>

    <?php
        $recentPosts 
    = new WP_Query();
        
    $recentPosts->query('showposts=10&cat=3');
    ?>
    <?php 
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    <div id="h2-memorial">
        <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    </div>
    <?php the_excerpt(); ?>
    <?php 
    endwhile; ?>


    <div class="page-nav">
    <?php wp_pagenavi(); ?>    </div>

    <!--page.php end-->
    </div>
    </div>
    <?php endif; ?>
    <?php get_sidebar
    (' '); ?>
    <?php get_footer
    (' '); ?>
    Thank you in advance!

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,146
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Try posts_per_page=10 as showposts was deprecated source

  3. #3
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @cpradio

    Dude you're friggin awesome! That's giving me the 10 posts per page! Can you help me get page navigation to work now?! There are 14 memorials only 10 are showing on http://stlheroinhelp.org/memorials/ - I can't get page navigation on the bottom like it is on http://stlheroinhelp.org/?s=heroin (example of navigation on bottom).

    Not sure what code I'm missing above ^^^ or what's out of place/out of order.

  4. #4
    Non-Member
    Join Date
    Jun 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where is next_posts_link() and previous_posts_link() function? you should add these function in your page. for more details you can search the function in wordpress.org.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,146
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by scott g View Post
    @cpradio

    Dude you're friggin awesome! That's giving me the 10 posts per page! Can you help me get page navigation to work now?! There are 14 memorials only 10 are showing on http://stlheroinhelp.org/memorials/ - I can't get page navigation on the bottom like it is on http://stlheroinhelp.org/?s=heroin (example of navigation on bottom).

    Not sure what code I'm missing above ^^^ or what's out of place/out of order.
    Okay, I am unsure at this point, but some debugging may help to see what is going on. Replace the following code
    PHP Code:
    <?php wp_pagenavi(); ?>
    With
    PHP Code:
    <?php var_dump($GLOBALS['wp_query']);
    wp_pagenavi(); ?>
    That should produce some kind of output at the bottom of the page, I would need that copied/pasted here so I can see what the value of $GLOBALS['wp_query'] is (as the WP-PageNavi plugin is dependent on that value)

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,146
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, I have it solved

    Replace
    PHP Code:
        $recentPosts = new WP_Query(); 
        
    $recentPosts->query('posts_per_page=10&cat=3'); 
    With
    PHP Code:
        $recentPosts = new WP_Query( array( 'cat' => 3'posts_per_page' => 10'paged' => get_query_var('paged') ) ); 
    Then replace
    PHP Code:
    <?php      wp_pagenavi(); ?>
    With
    PHP Code:
    <?php      wp_pagenavi( array( 'query' => $recentPosts ) ); ?>

  7. #7
    SitePoint Enthusiast scott g's Avatar
    Join Date
    Jun 2012
    Location
    STL . MO
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CPRADIO!

    You are the friggin MAN! I really can't thank you enough! Thank you thank you thank you! You solved what's been eating at me for 2-entire days.. And you were just helping. Thank you so much!

    -Scott G.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •