Forums

[resolved] wp-page-numbers incorrectly displaying on news only home page (3 posts)

  1. Ninja Master Jimmy Wong-Fu
    Member
    Posted 1 year ago #

    I have a home page with the following code above the loop to show News posts only.

    <?php if (have_posts()) : ?>
    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=10'.'&paged='.$paged.'&category_name=News');
    ?>

    I also have wp-post-numbers installed, which is displayed as follows:

    <?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>

    For some reason the wp-page numbers cannot display the page numbers properly. For example, if I set it to display 10 posts per page and I have 18 posts in total I would expect it to show only two page numbers (one for each page - ten on the first; eight on the next). Instead It shows three, and if you click on the third one it displays an error (no posts found).

    Any ideas or workaround?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    try this:

    <?php if (have_posts()) : ?>
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=10'.'&paged='.$paged.'&category_name=News');
    ?>
  3. Ninja Master Jimmy Wong-Fu
    Member
    Posted 1 year ago #

    As long as the above code is placed above the wp-page-nembers code it works perfectly!!

    For example:

    <?php if (have_posts()) : ?>
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=10'.'&paged='.$paged.'&category_name=News');
    ?>

    <?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>

    Then add the loop

    Thanks a million for your quick response!!!!!

Topic Closed

This topic has been closed to new replies.

About this Topic