php previous_posts_link not working with wp_query

Discussion in 'WordPress' started by sixrfan, Jul 6, 2011.

  1. #1
    on this page, it's a regular wordpress page (not archive.php or category.php or anything like that).

    in the page, I have the following php code which should pull in the 15 most recent posts, plus, it should an "Older Entries" link at the bottom to early entries.

    
    <?php
    $custom_query = new WP_Query( 'posts_per_page=15&cat=1' );
    if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    
    <h3><?php the_title(); ?></h3>
    <h6><?php the_time('F j, Y') ?></h6>
    <?php the_content(); ?>
    <hr class="homenews" />
    <?php previous_posts_link('« Older Entries', 5) ?>
    <?php endwhile; else : ?>
    
    <h3>Sorry...</h3>
    <p>No posts were found.</p>
      
    <?php endif; ?>
    
    PHP:

    but for some reason the "Older Entries" link is not appearing. how come?

    please advise. thanks in advance!
     
    sixrfan, Jul 6, 2011 IP
  2. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    тнє Sufi, Jul 6, 2011 IP
  3. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    well i replaced what i had before with the code below (based on that solution), but the Pagination still does not appear after the 15th post.

    <?php
         query_posts( array(
          'posts_per_page' => 15,
          'cat' => '1', /* change CategoryID with exact value */
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
     ));
    ?>
    PHP:
    how come the pagination isn't appearing?

    also, i'd like to have the published date appear right below the title of each post. how do i do that?

    please advise. thanks!
     
    sixrfan, Jul 6, 2011 IP
  4. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It should have worked. Update your permalink structure. If your files are not writable, then update your .htaccess manually. And then try again.

    If problem not solved after this, then add following code instead of your current code:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') :1;
    query_posts( array (
          'posts_per_page' => 15,
          'cat' => '1',
          'paged' => $paged,
     ));
    ?>
    PHP:
    To show post published date. put this code where you want to show it:
    <?php get_the_date(); ?>
    PHP:
     
    тнє Sufi, Jul 6, 2011 IP
  5. rakesh kumar

    rakesh kumar Active Member

    Messages:
    393
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #5
    Include pagination code after the loop of query-post.
     
    rakesh kumar, Jul 7, 2011 IP
  6. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    so how do it put it all together? like this?

    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') :1;
    query_posts( array (
          'posts_per_page' => 15,
          'cat' => '1',
          'paged' => $paged,
     ));
    <?php get_the_date(); ?>
    <?php previous_posts_link('« Older Entries', 5) ?>
    ?>
    
    PHP:



    php is clearly not my strong suite...
     
    sixrfan, Jul 7, 2011 IP
  7. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Adding pagination code after query post will not solve it. And also there is error in your code. If you are interested, then you can give me your wp-admin, and I can look for it.

    Your code shoud be:
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') :1;
    query_posts( array (
          'posts_per_page' => 15,
          'cat' => '1',
          'paged' => $paged,
     ));
    get_the_date();
    previous_posts_link('« Older Entries', 5);
    ?>
    PHP:
    But it will not work.
     
    тнє Sufi, Jul 7, 2011 IP
  8. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    you mean it will not work until the error that you see is cleaned up? i'd rather not provide wp-admin credentials. i'd prefer to just paste in a section of code where you believe the error resides. what file's code would you like to see?

    i appreciate you bearing with me here...
     
    sixrfan, Jul 7, 2011 IP
  9. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ok no problem. You have said that, it is not working on your /store-news/ page. Did you created any custom page template for that? Or using that page as your blog page? If that is your blog page, then give me index.php (or home.php if any). If using custom page, give me code of that page.
     
    тнє Sufi, Jul 7, 2011 IP
  10. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #10
    sixrfan, Jul 7, 2011 IP
  11. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Without seeing your template structure, I can not help much. Paste the codes you are using for the custom query. Are you using them directly in the page using PHP Exec?
     
    тнє Sufi, Jul 7, 2011 IP
  12. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #12
    it's just a standard run of the mill wordpress page. and in the HTML tab of that page's editor, i place the code that you instructed me to.

    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') :1;
    query_posts( array (
          'posts_per_page' => 15,
          'cat' => '1',
          'paged' => $paged,
     ));
    get_the_date();
    previous_posts_link('« Older Entries', 5);
    ?>
    
    PHP:
    you can see the results on this test page. but still there's no Older Entries link at the bottom. Nor do the post dates appear below the post titles. what am i missing?
     
    sixrfan, Jul 7, 2011 IP
  13. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    As you are using those codes from PHP Exec, they are actually being placed on page.php
    Using custom page template will be the best solution. It's tough to give solution from this situation. You can either give me access, so I can check, or you can send me all theme files to look for it.
    Solution will be either custom page template or using a is_page condition in home.php, that is also similar to custom page.
     
    тнє Sufi, Jul 7, 2011 IP
  14. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #14
    i prefer not to grant access but which file codes would you like to see? one of the files from the PHP Exec plugin that I'm using?
     
    sixrfan, Jul 7, 2011 IP
  15. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    No sent me all files under your /wp-content/themes/your-current-theme/
     
    тнє Sufi, Jul 8, 2011 IP
  16. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #16
    Let's try another approach. I setup another site with the same functionality. This other site just uses the basic TwentyTen theme. No customization. This page of the new site is using the code below (a replica of what's on the other site), yet the "Older Entries" link still does NOT appear at the bottom of the page. Nor does the Date appear right below the post title.

    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') :1;
    query_posts( array (
          'posts_per_page' => 3,
          'cat' => '3',
          'paged' => $paged,
     ));
    get_the_date();
    previous_posts_link('« Older Entries', 5);
    ?>
    
    PHP:
    I just PM'd you the access user login I created for you.

    Please advise. thanks!
     
    sixrfan, Jul 9, 2011 IP
  17. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I have just sent you one custom template for twenty ten them. Try it.
    Thanks.
     
    тнє Sufi, Jul 11, 2011 IP
  18. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #18
    ok, i uploaded that page to the twentyten folder. however when i go to that page editor, i don't see this new option in the "Template" dropdown. shouldnt it appear there? what am i missing?
     
    sixrfan, Jul 11, 2011 IP
  19. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    You did not miss anything. That is actually a page, not a full template. So it will be under twenty ten theme.
    Check the image.
    Edit Themes ‹ Test Blog — WordPress.jpg
    Check this page: http://greenrefurbishing.com/wordpress/?page_id=8
    I have set category 3 with 3 posts per page.
     
    тнє Sufi, Jul 11, 2011 IP
  20. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #20
    i'm really confused as to how ?page_id=8 connects to this page-test-page.php file? when i'm in the editor for page 8, there's nothing to select that says "hey, use the page-test-page.php template".

    please advise. thanks for bearing with me.
     
    sixrfan, Jul 12, 2011 IP