logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
Need help with wp-page-navi

Hi There,

I have a custom wordpress theme that I have built. It has a portfolio page that pulls in post from a particular category.

My theme has a custom back-end that allows the user to determine how many portfolkio items to display on the page.

Everything is working fine, but the issue I am having is with wp-page-navi. The page navi shows up but when you click one of the pages, it just stays on the same page (ie. it saysd page 1 of 3 and when you click page 2 it just stays on page 1).

I had a similar problem on my blog page, which was fixed by an expert on here:
http://www.wpquestions.com/question/show/id/337

I'm assuming I need to do something similar but my "loop" is a bit more complicated than my blog loop. Here is the loop that pulls in the posts. Any help is greatly appreciated:


<?php
//$category_id = get_cat_id($featport);
$category_id = get_post_meta($post->ID, '_multiple_portfolio_cat_id', true);
$posts_p_p = stripslashes(get_settings( $shortname."_portitems" ) );
$query_string ="posts_per_page=$item_count&cat=$category_id&posts_per_page=$posts_p_p";

query_posts($query_string);

$count = 0;
$col = 0;

if (have_posts()) : while (have_posts()) : the_post();

$count++;
$col ++;
$mod = ($count % 3 == 0) ? 0 : 3 - $count % 3;
?>

This question has been answered.

WP Answers | 04/28/10 at 6:43pm Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    04/28/10
    6:57pm
    Milan Petrovic says:

    WP PageNavi works with the page WP_Query object, not a loop. query_posts is not exactly good choice for what you need. You need to change $wp_query object. Replace your query_posts with something like this:

    <?php

    global $wp_query;
    $master_wpq = $wp_query;
    $wp_query = new WP_Query($query_string);

    ?>


    After your loop ends, it's good to restore old query:

    <?php

    $wp_query = $master_wpq;

    ?>

    • 04/28/10 7:06pm

      WP Answers says:

      Thank you very much for this code.

      It isn;t quite working as required, but I think it is closer. Perhaps I didn;t add your code correctly? Can you check this to see if it is right?

      After added the code, the pages sort of work. When you click page 2, it goes to page 2 (in the address bar /page/2/), but the "active state" on the page-navi is still on page 1, and the content is the same as page 1.

      Any ideas what could be wrong? (sorry I'm fairly new to custom wordpress coding)

      New code:


      <?php
      //$category_id = get_cat_id($featport);
      $category_id = get_post_meta($post->ID, '_multiple_portfolio_cat_id', true);
      $posts_p_p = stripslashes(get_settings( $shortname."_portitems" ) );
      $query_string ="posts_per_page=$item_count&cat=$category_id&posts_per_page=$posts_p_p";

      global $wp_query;
      $master_wpq = $wp_query;
      $wp_query = new WP_Query($query_string);

      $count = 0;
      $col = 0;

      if (have_posts()) : while (have_posts()) : the_post();

      $count++;
      $col ++;
      $mod = ($count % 3 == 0) ? 0 : 3 - $count % 3;
      ?>

  • avatar
    Last edited:
    04/28/10
    7:23pm
    Lew Ayotte says:

    You need to add the $paged stuff to your loop...

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $category_id = get_post_meta($post->ID, '_multiple_portfolio_cat_id', true);

    $posts_p_p = stripslashes(get_settings( $shortname."_portitems" ) );

    $query_string ="posts_per_page=$item_count&cat=$category_id&posts_per_page=$posts_p_p&paged=$paged";

    query_posts($query_string);


    BTW, you have two "posts_per_page" in that query_string... you probably want to remove one :)

    Lew

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.