WordPress自定义搜索-分页

时间:2014-10-22 作者:boomdrak

我已经编写了一个自定义wordpress搜索。问题是分页不起作用。

分页(1、2、3、4、5>>)显示在网站上,但当我按第2页(或其他任何内容)时,不会显示新的查询数据。它只显示我的第一页(前9个产品)。

有人能帮我找出我做错了什么吗?:)

请查看网页:http://tevodekk.kamy.no/felgalle/

$display_count = 2;
global $wp_query, $paged;
 $pages = $wp_query->max_num_pages;
//LAGER SØKOUTPUT
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
echo "paged " . $paged;
$showposts = 10;
    $args = array(
        \'posts_per_page\' => 20,
        \'post_type\' => \'any\',
        \'post__in\'      => $WPIDs,
        \'orderby\' => \'meta_value\',
        \'meta_key\' => \'cf_dimensjon\',
        \'order\' => \'ASC\',
        \'number\'     =>  $display_count,
        \'paged\'       =>  $paged

);

$wp_query  = new WP_Query( $args );


 //The Loop
while ( $wp_query ->have_posts() ) : $wp_query  ->the_post();
global $product;
//echo $query->request;
if((int)$product->stock > 0 ){

 $url2 = get_permalink( $product_id );
 $url = $product->add_to_cart_url($p);
  $price = get_post_meta( get_the_ID(), \'_regular_price\', true);
  $stock = get_post_meta( get_the_ID(), \'_stock\', true);
  $pic = wp_get_attachment_url( get_post_thumbnail_id($post->ID, \'thumbnail\') );
  $bredde = array_shift(woocommerce_get_product_terms($product->id, \'cf_felgbredde\',               \'names\'));
    $bredde = get_post_meta(  get_the_ID(), \'cf_felgbredde\', true );
    $hoyde = array_shift(woocommerce_get_product_terms($product->id, \'cf_hoyde\',       \'names\'));
    $hoyde = get_post_meta(  get_the_ID(), \'cf_hoyde\', true );
    $dim = array_shift(woocommerce_get_product_terms($product->id, \'cf_dimensjon\',             \'names\'));
    $dim = get_post_meta(  get_the_ID(), \'cf_dimensjon\', true );
    $innpress = array_shift(woocommerce_get_product_terms($product->id, \'pa_felg-      bredde\', \'names\'));
    $innpress = get_post_meta(  get_the_ID(), \'cf_innpress\', true );
    $produktgruppeny = array_shift(woocommerce_get_product_terms($product->id,             \'pa_produktgruppeny\', \'names\'));


  echo  \'<div>
  <div style="float:left;"><a href="\'.$url2.\'"><img width="64" height="64"       src="\'.$pic.\'" class="attachment-shop_catalog wp-post-image" alt="Standard bilde -       sommerdekk" style="padding-right: 10px;"></a></div>
        <div style="float:left;width: 390px;padding-top: 12px"><h3><a       href="\'.$url2.\'">\'. the_title( $before, $after, $echo ) .\'</a><span class="amount"       style="font-weight: normal;color: #f7f2f7;" >\'  . \' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;       &nbsp; &nbsp;\'   . \' \'. \'</span></h3>
        <span style="color:#FFFFFF;"> Dim: \'.$dim.\' Innpress: \'.$innpress .  \' Lager       : \' . $stock . \' </span></div>
        <div style="float:left;margin-left: 45px;padding-top: 12px;"><form       class="cart" method="post" enctype="multipart/form-data">
        <div class="quantity buttons_added" style="float: left; margin-right: 11px;">      <input type="button" value="-" class="minus">
        <input type="number" step="1" min="1" name="quantity" value="1"       title="Antall" class="input-text qty text" size="4">
        <input type="button" value="+" class="plus"></div>
        <input type="hidden" name="add-to-cart" value="\'.get_the_ID().\'">
        <button type="submit" class="single_add_to_cart_button button       alt">Kjøp</button>&nbsp; \' . $price . \' kr \' . \'
        </form></div>
      <div style="clear:both;border-bottom: 1px solid #827f82;margin-bottom:       0px;padding-top: 0px;"></div>
    </div>\'; }
  //

  endwhile;
  wp_pagenavi();
删除了偏移量,效果很好

1 个回复
SO网友:boomdrak

Working code:

$display_count = 2;
global $wp_query, $paged;
$pages = $wp_query->max_num_pages;
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$offset =  $page - 1;
$showposts = 10;
    $args = array(
        \'showposts\' => 20,
        \'post_type\' => \'any\',
        \'post__in\'      => $WPIDs,
        \'orderby\' => \'meta_value\',
        \'meta_key\' => \'cf_dimensjon\',
        \'order\' => \'ASC\',
        \'number\'     =>  $display_count,
        \'paged\'       =>  $paged

);

$wp_query  = new WP_Query( $args );

 //The Loop
while ( $wp_query ->have_posts() ) : $wp_query  ->the_post();
global $product;
//echo $wp_query->request;

if((int)$product->stock > 0 ){

 $url2 = get_permalink( $product_id );
 $url = $product->add_to_cart_url($p);
 $price = get_post_meta( get_the_ID(), \'_regular_price\', true);
$stock = get_post_meta( get_the_ID(), \'_stock\', true);
$pic = wp_get_attachment_url( get_post_thumbnail_id($post->ID, \'thumbnail\') );
$bredde = array_shift(woocommerce_get_product_terms($product->id, \'cf_felgbredde\',         \'names\'));
$bredde = get_post_meta(  get_the_ID(), \'cf_felgbredde\', true );
$hoyde = array_shift(woocommerce_get_product_terms($product->id, \'cf_hoyde\', \'names\'));
$hoyde = get_post_meta(  get_the_ID(), \'cf_hoyde\', true );
$dim = array_shift(woocommerce_get_product_terms($product->id, \'cf_dimensjon\', \'names\'));
$dim = get_post_meta(  get_the_ID(), \'cf_dimensjon\', true );
$innpress = array_shift(woocommerce_get_product_terms($product->id, \'pa_felg-bredde\', \'names\'));
$innpress = get_post_meta(  get_the_ID(), \'cf_innpress\', true );
$produktgruppeny = array_shift(woocommerce_get_product_terms($product->id,     \'pa_produktgruppeny\', \'names\'));


echo  \'<div>
     <div style="float:left;"><a href="\'.$url2.\'"><img width="64" height="64"     src="\'.$pic.\'" class="attachment-shop_catalog wp-post-image" alt="Standard bilde -     sommerdekk" style="padding-right: 10px;"></a></div>
      <div style="float:left;width: 390px;padding-top: 12px"><h3><a     href="\'.$url2.\'">\'. the_title( $before, $after, $echo ) .\'</a><span class="amount"     style="font-weight: normal;color: #f7f2f7;" >\'  . \' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;     &nbsp; &nbsp;\'   . \' \'. \'</span></h3>
      <span style="color:#FFFFFF;"> Dim: \'.$dim.\' Innpress: \'.$innpress .  \' Lager :     \' . $stock . \' </span></div>
      <div style="float:left;margin-left: 45px;padding-top: 12px;"><form class="cart"     method="post" enctype="multipart/form-data">
        <div class="quantity buttons_added" style="float: left; margin-right: 11px;">    <input type="button" value="-" class="minus">
        <input type="number" step="1" min="1" name="quantity" value="1"     title="Antall" class="input-text qty text" size="4">
        <input type="button" value="+" class="plus"></div>
        <input type="hidden" name="add-to-cart" value="\'.get_the_ID().\'">
        <button type="submit" class="single_add_to_cart_button button     alt">Kjøp</button>&nbsp; \' . $price . \' kr \' . \'
        </form></div>
    <div style="clear:both;border-bottom: 1px solid #827f82;margin-bottom:     0px;padding-top: 0px;"></div>
  </div>\'; }
//

endwhile;
结束

相关推荐

WordPress Search

我正试图在我的一个网站上写一个搜索功能,它似乎并没有吸引任何页面,只有帖子。下面是代码。搜索表单: <form role=\"search\" method=\"get\" id=\"searchform\" action=\"<?php echo home_url( \'/\' ); ?>\"> <input type=\"text\" value=\"Search\" onblur=\"if (this.value