我有一个带有以下代码的博客主页home.php
:
<div id="primary">
<div id="content" role="main">
<h2 class="page-title">Featured Products</h2>
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
wp_reset_query();
mp_display_products(\'&post_type=product&paged=\' . $paged, $display) ; ?>
<div class="clear index-space"></div>
</div><!-- #content -->
</div><!-- #primary -->
现在主页运行正常,但是?paged=2抛出错误404。不知道为什么。在产品类别中,分页也很好。
任何帮助都将不胜感激。
EDIT
下面是函数的代码
mp_display_products()
function mp_display_products($query = \'\', $display){
wp_reset_query();
//$new_query_wp = new WP_Query($query) ;
$new_query = query_posts($query) ;
wp_simple_pagination(/*array(\'base\' => \'store/products\')*/);
$i = 1 ;
if($display == \'row\'){
echo \'<table summary="Display featured products in rows" id="products-list">\' ;
}
if ( $new_query != \'\' ) : ?>
<?php /* Start the Loop */ ?>
<?php foreach ($new_query as $post) {
$sale_price = get_post_meta($post->ID, \'mp_sale_price\', true) ;
$sale_price = $sale_price[0] ;
$price = get_post_meta($post->ID, \'mp_price\', true) ;
//Determines end_price
if($sale_price == 0){
//End price is normal price
$end_price = \'$\'.$price[0] ;
}
else{
//Or end price is sale price
$end_price = \'$\'.$sale_price ;
}
//If theres a sale price
if($sale_price != 0){
//We display
$price = \'RRP: <span class="price">$\'.$price[0].\'</span>\' ;
}
else{
//Or we don\'t
$price = "" ;
}
?>
<?php //We display each product
//Let\'s shorten the title string
$title = $post->post_title ;
$string_size = 25 ;
//Test if string is longer that string_size
if(strlen($title) > $string_size){
$title = substr($title, 0, $string_size).\'...\' ;
}
//Check if we need a grid of a row display
if($display == \'grid\'){
//Inventory
$inventory = get_post_meta($post->ID, \'mp_inventory\', true) ;
?>
<article class="post-<?php echo $post->ID ; ?> product post-product-<?php echo $i ; ?>">
<h2><a href="<?php echo get_permalink( $post->ID ) ; ?>" title="View product: <?php echo $post->post_title ; ?>"><?php echo $title ; ?></a></h2>
<?php //Test if there is a thumbnail
if(has_post_thumbnail($post->ID)){
echo \'<div class="image_product">\' ;
mp_product_image( $echo = true, $context = \'list\', $post->ID, $size = 200 ) ;
echo \'</div><!--end thumbnail-->\' ;
}
else{
echo \'<div class="image_product">
<img src="\'.get_template_directory_uri().\'/images/default-product.png" alt="Default image for product" />
</div>\' ;
}
?>
<div class="product-details">
<span class="product-old-price"><?php echo $price ; ?></span>
<span class="product-detail-link"><a href="<?php echo get_permalink($post->ID) ; ?>">Details</a></span>
<span class="product-price"><?php echo $end_price ; ?></span>
<?php
//If inventory isn\'t empty
if(!empty($inventory)){
mp_buy_button( $echo = true, $context = \'list\', $post_id = $post->ID ) ;
}
?>
</div>
</article>
<?php
}//end grid display
//Start row
else{
echo \'<tr>
<td>\' ;
if(has_post_thumbnail($post->ID)){
echo \'<div class="image_product">\' ;
mp_product_image( $echo = true, $context = \'list\', $post->ID, $size = 88 ) ;
echo \'</div><!--end thumbnail-->\' ;
}
else{
echo \'<div class="image_product">
<img src="\'.get_template_directory_uri().\'/images/default-product.png" alt="Default image for product" />
</div>\' ;
}
echo \'</td>
<td class="title"><h2><a href="\'.get_permalink( $post->ID ).\'" title="View product: \'.$post->post_title.\'">\'.$post->post_title.\'</a></h2>
<span class="product-detail-link"><a href="\'.get_permalink( $post->ID ).\'">Details</a></span></td>
<td>Customer Rating:\' ;
if(function_exists(\'kk_star_ratings\')) : echo kk_star_ratings($post->ID); endif;
$comments_count = wp_count_comments( $post->ID );
echo \'<span class="reviews">Reviews (\'.$comments_count->approved.\')</span></td>
<td class="price"><span class="product-price">\'.$end_price.\'</span>\';
mp_buy_button( $echo = true, $context = \'list\', $post_id = $post->ID ) ;
echo \'</td></tr>\' ;
}
$i++ ;
if($i == 4){ $i = 1 ; }
?>
<?php }
if($display == \'row\'){
echo \'</table>\' ;
}
?>
<?php else : ?>
<?php endif; ?>
<div class="clear index-space"></div>
<?php
wp_simple_pagination(array(\'base\' => \'store/products\'));
}